Writing Numeric Data to a File

S

Satish Chimakurthi

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top