[Tutor] Re: creating text files

Shantanoo Mahajan python at dhumketu.cjb.net
Thu Dec 11 13:04:23 EST 2003


+++ Stanfield, Vicki {D167~Indianapolis} [11-12-03 11:59 -0500]:
| A follow-up question if you don't mind....
| 
| I open a log file while my program is running, but sometimes the program
| crashes and leaves no log file. Is there any way to write the file prior
| to when I actually close it. I guess I could close it and reopen it, but
| I'd rather just flush the output to the file.
| 
| --vicki
| 

f=open('test.file','w')
f.write('this is a test')
f.flush()
....
....
....
f.close()


f.flush() will write the files to HDD. It flushes the I/O buffer.

Shantanoo



More information about the Tutor mailing list