Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:59:48+00:00 2026-06-10T11:59:48+00:00

How can I save data to a file (that I will plot later on)

  • 0

How can I save data to a file (that I will plot later on) effectively?

I have got this from my research:

#Open new data file
f = open("data2.txt", "w")
f.write( str(yEst)  )      # str() converts to string
f.close()

Here is a bit of my code so far:

for i in drange2(0, 2*math.pi + 0.0634665182543392 , 0.0634665182543392):
    for x in range(1,N+1):
       yEst = yEst + a * cos(x* i)
#print yEst
f.write( str(yEst)  )      # str() converts to string
yEst=0
f.close()

Now, when I go and open my file “data2.txt” I can not read the data because it is not ‘organized’. How can I go to the next line using the f.write( str(yEst) ) so that I have a column that contains my ‘yEst’ data into the file “data2.txt?
Thank you in advance for your consideration 🙂

PS: yEst looks like (in the data2.txt file): 48.901347147148.605785828748.114506165947.429486 .. and I want it as a column: –>

48.9013471471 (new line)
48.6057858287 (new line)
48.1145061659 (new line)
47.4294863684    
etc ..                        
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:59:50+00:00Added an answer on June 10, 2026 at 11:59 am

    Do you mean to say you’d like each point of data on its own line, like this?

    48.9013471471
    48.6057858287
    48.1145061659
    47.4294863684
    

    If so, then you might like to try something like this:

    for i in drange2(0, 2*math.pi + 0.0634665182543392 , 0.0634665182543392):
        for x in range(1,N+1):
           yEst = yEst + a * cos(x* i) 
           f.write( str(yEst) + "\n"  )
    f.close()
    

    Firstly, to write each data point to the line, it needs to be ‘inside’ the loop – that’s why I’ve added extra space to the line before I call f.write.

    The second thing I added is + "\n" – this will add the new line character to the end of the line. You can change it to whatever you’d like! A couple of examples:

    f.write( str(yEst) + " " ) will add one space after each data point:

    48.9013471471 48.6057858287 48.1145061659 47.4294863684
    

    f.write( str(yEst) + "|" ) will add one pipe character after each data point:

    48.9013471471|48.6057858287|48.1145061659|47.4294863684|
    

    If, on the other hand, you’d rather just save the data as an array, try the below:

    yEst = 0 # or some initial value
    yEstArray = []
    for i in drange2(0, 2*math.pi + 0.0634665182543392 , 0.0634665182543392):
        for x in range(1,N+1):
           yEst = yEst + a * cos(x* i) 
           yEstArray.append(yEst)
    

    Then, you can iterate over the array like so:

    for yEst in yEstArray:
        do something with yEst
    

    or

    for yEst, index in enumerate(yEstArray):
        do something with yEst and its index
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I save data from an Excel sheet to .RData file in R?
I have an application that imports data from a pickled file. It works just
So I have an air application that I want to save data from into
Is there a way that i can save data on each step in wizard
I want to setup a table that can: Save the data on the user's
I try to create a form that can save a person's form data so
I'm developing web app that user can save his/her work to server. The data
The principle of sessions is to save data on server side that can be
I have got this project that uses excel for some calculation. This excel is
How can you have a function or something that will be executed before your

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.