Re: [Tutor] do I need f.close()

2008-06-12 Thread Alan Gauld
"Marilyn Davis" <[EMAIL PROTECTED]> wrote happy about letting the os close read only files, its really for writing that you want to be explicit. Alan, will the file close, even if it was opened for writing, when the program ends? I know it stays open if you're interactive, but otherwise

Re: [Tutor] do I need f.close()

2008-06-12 Thread Marilyn Davis
On Thu, June 12, 2008 4:32 pm, Alan Gauld wrote: > "dave selby" <[EMAIL PROTECTED]> wrote > > >> The whole topic came up because I just finished reading 'learning >> python' 3rd edition OReilly as a refresher where there are multiple >> instances of suggesting that you do the exact opposite eg ...

Re: [Tutor] do I need f.close()

2008-06-12 Thread Alan Gauld
"dave selby" <[EMAIL PROTECTED]> wrote The whole topic came up because I just finished reading 'learning python' 3rd edition OReilly as a refresher where there are multiple instances of suggesting that you do the exact opposite eg ... LP is a tutorial book so does not always teach industry st

Re: [Tutor] do I need f.close()

2008-06-12 Thread Terry Carroll
On Wed, 11 Jun 2008, dave selby wrote: > The whole topic came up because I just finished reading 'learning > python' 3rd edition OReilly as a refresher where there are multiple > instances of suggesting that you do the exact opposite eg ... > > [line.rstrip() for line in open('myfile')] ... p361

Re: [Tutor] do I need f.close()

2008-06-11 Thread dave selby
Thanks for all your help guys, I am getting a strong consensus that f.close() should be used everywhere, reading files as well as writing files and not to rely on the PVM to do clean-up for you. The whole topic came up because I just finished reading 'learning python' 3rd edition OReilly as a refr

Re: [Tutor] do I need f.close()

2008-06-10 Thread Danny Yoo
f = open(conf, 'w') f.writelines(lines) f.close() Is it as safe to use the following open(conf, 'w').writelines(lines) ie no close() to flush the data, but also not assigned an object name so am I right in thinking that as the object is 'reclaimed' close() is automatically called ?

Re: [Tutor] do I need f.close()

2008-06-10 Thread bob gailer
dave selby wrote: Hi All, Up to now I when I need to write some data to a file I have been purposely using close() f = open(conf, 'w') f.writelines(lines) f.close() Is it as safe to use the following open(conf, 'w').writelines(lines) ie no close() to flush the data, but also not assigne

Re: [Tutor] do I need f.close()

2008-06-10 Thread Marc Tompkins
On Tue, Jun 10, 2008 at 10:07 AM, dave selby <[EMAIL PROTECTED]> wrote: > Hi All, > > Up to now I when I need to write some data to a file I have been > purposely using close() > > f = open(conf, 'w') > f.writelines(lines) > f.close() > > Is it as safe to use the following > > open(conf, 'w')

Re: [Tutor] do I need f.close()

2008-06-10 Thread Kent Johnson
On Tue, Jun 10, 2008 at 1:07 PM, dave selby <[EMAIL PROTECTED]> wrote: > Hi All, > > Up to now I when I need to write some data to a file I have been > purposely using close() > > f = open(conf, 'w') > f.writelines(lines) > f.close() > > Is it as safe to use the following > > open(conf, 'w').w

Re: [Tutor] do I need f.close()

2008-06-10 Thread Alan Gauld
"dave selby" <[EMAIL PROTECTED]> wrote Up to now I when I need to write some data to a file I have been purposely using close() f = open(conf, 'w') f.writelines(lines) f.close() Is it as safe to use the following open(conf, 'w').writelines(lines) In theory yes, but in practice its muc

Re: [Tutor] do I need f.close()

2008-06-10 Thread W W
On Tue, Jun 10, 2008 at 12:07 PM, dave selby <[EMAIL PROTECTED]> wrote: > Hi All, > > Up to now I when I need to write some data to a file I have been > purposely using close() > > f = open(conf, 'w') > f.writelines(lines) > f.close() > > Is it as safe to use the following > > open(conf, 'w').