Re: Simple file writing techiques ...

2006-07-19 Thread Simon Forman
cdecarlo wrote: > Hello, > > I've often found that I am writing little scripts at the interpretor to > read a text file, perform some conversion, and then write the converted > data back out to a file. I normally accomplish the above task by > > Any suggestions, > > Colin You should check out

Re: Simple file writing techiques ...

2006-07-19 Thread BartlebyScrivener
See also this recent discussion on techniques for making sure you get the file closed, even if there is an exception. http://tinyurl.com/fryrv rd -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple file writing techiques ...

2006-07-19 Thread Ant
Whoops: > outfile = open(out_f) outfile = open(out_f, 'w') may be better ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple file writing techiques ...

2006-07-19 Thread Ganesan Rajagopal
> cdecarlo <[EMAIL PROTECTED]> writes: > fout = open('somefile','w') > for line in convertedData: > fout.write("%s\n" % line) > fout.close() > -- or -- > fout = open('somefile','w') > fout.write("%s" % '\n'.join(convertedData)) > fout.close() > ... or maybe some hybrid of the two which

Re: Simple file writing techiques ...

2006-07-19 Thread Ant
> fout = open('somefile','w') > for line in convertedData: > fout.write("%s\n" % line) > fout.close() > > -- or -- > > fout = open('somefile','w') > fout.write("%s" % '\n'.join(convertedData)) > fout.close() I shouldn't think it matters too much which of these you use - time them and see what h

Re: Simple file writing techiques ...

2006-07-19 Thread Will McGugan
cdecarlo wrote: > > fout = open('somefile','w') > for line in convertedData: > fout.write("%s\n" % line) > fout.close() > > -- or -- > > fout = open('somefile','w') > fout.write("%s" % '\n'.join(convertedData)) > fout.close() > I'd go for something like... fout = open('somefile','w') fout.wri

Simple file writing techiques ...

2006-07-19 Thread cdecarlo
Hello, I've often found that I am writing little scripts at the interpretor to read a text file, perform some conversion, and then write the converted data back out to a file. I normally accomplish the above task by reading the lines of the entire file into a list, preforming some function to that