Writing Numeric Data to a File

Satish Chimakurthi skchim0 at engr.uky.edu
Mon Jun 14 16:25:15 EDT 2004


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040614/7cfa34f4/attachment.html>


More information about the Python-list mailing list