[Tutor] file opening modes

Jimmy verma jim_938 at hotmail.com
Wed Sep 10 20:06:21 EDT 2003


Thanks for giving your suggestions regarding creating filenames dynamically. 
Actually i am caught in a problem with this.

I am opening files in a loop and writing information in it and then 
sometimes the same file is opened and i append some information.

The problem starts here.

If i use open(filename,'w')
or write mode for opening file then as according to the expected behaviour 
of write mode it erases the contents before writing in the file.
So i decided to use open(filename, 'a')
i.e. append mode so that i can append information to the file while i am 
running the program.

Now suppose i have

./progname.py  somefiletoextractinfo

and three files are generated

a.txt, b.txt, c.txt


Now suppose if i run the program again then i get into problem because now 
again these three files will be appending the information in the existing 
files which i created last time i run the program.

I know which filenames i will be creating dynamically so i dont want these 
files to be already present when i run the program again.

I hope i am right with the append mode or should i choose some different 
mode.


Thanks again for your suggestions.


With best regards,

J+

_________________________________________________________________
Hey there, NRIs! Send money home. 
http://server1.msn.co.in/msnleads/citibankrca/citibankrca2.asp?type=txt Use 
Citibank RCA




More information about the Tutor mailing list