Writing Numeric Data to a File

Discussion in 'Python' started by Satish Chimakurthi, Jun 14, 2004.

  1. Hi all,

    I have written some data to a file with the following code. I have copied the OUTPUT hereunder.

    xdisp=open('ansys_xdisp.dat','w')
    xdisp.writelines("time")
    xdisp.writelines(' ')
    xdisp.writelines("xdisp")
    xval_new = 0
    time_structure = 0.005
    xdisp.writelines('\n')
    xdisp.writelines(str(time_structure))
    xdisp.writelines(' ')
    xdisp.writelines(str(xval_new))
    xdisp.writelines(' ')
    xdisp.close()


    OUTPUT (in file ansys_xdisp.dat):

    time xdisp
    0.005 0

    However, I would like to write more efficient code and format the output properly so that it looks something like this:

    time xdisp
    0.005 0
    0.006 0.345
    ...
    ....


    Would someone please help me re-write this code properly to do the above and also point me to a reference wherein I could find all information about Formatting with Files.

    I did browse through Python's website to get some info about manipulating files. It's not elaborate enough, though. I would need to do more complex file-processing tasks shortly.


    Thanks in advance

    Regards,
    Satish
     
    Satish Chimakurthi, Jun 14, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,453
    HNguyen
    Dec 21, 2004
  2. Replies:
    3
    Views:
    603
    Dennis Lee Bieber
    Sep 2, 2005
  3. Replies:
    5
    Views:
    980
    X-Centric
    Jun 30, 2005
  4. darrel
    Replies:
    4
    Views:
    866
    darrel
    Jul 19, 2007
  5. jobs

    int to numeric numeric(18,2) ?

    jobs, Jul 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,017
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 22, 2007
Loading...

Share This Page