Re: Open and closing files

2006-11-30 Thread [EMAIL PROTECTED]
John Machin wrote: > Thomas Ploch wrote: > > Is it defined behaviour that all files get implicitly closed when not > > assigning them? > > > > Like: > > > > def writeFile(fName, foo): > > open(fName, 'w').write(process(foo)) > > > > compared to: > > > > > > def writeFile(fName, foo): > > f

Re: Open and closing files

2006-11-30 Thread John Machin
Thomas Ploch wrote: > Is it defined behaviour that all files get implicitly closed when not > assigning them? > > Like: > > def writeFile(fName, foo): > open(fName, 'w').write(process(foo)) > > compared to: > > > def writeFile(fName, foo): > fileobj = open(fName, 'w') > fileobj.w

Open and closing files

2006-11-30 Thread Thomas Ploch
Is it defined behaviour that all files get implicitly closed when not assigning them? Like: def writeFile(fName, foo): open(fName, 'w').write(process(foo)) compared to: def writeFile(fName, foo): fileobj = open(fName, 'w') fileobj.write(process(foo)) fileobj.clo

Re: Closing files

2004-11-30 Thread François Pinard
> Daniel Dittmar wrote: > >- that suggest a different solution; like declarations on local > >variables that say "call destructor when object goes out of scope" I did not follow all of this thread (that precise subject reoccurs once in a while, with some regularity), but I merely would like to po

Re: Closing files

2004-11-30 Thread Nick Coghlan
Daniel Dittmar wrote: - that suggest a different solution; like declarations on local variables that say "call destructor when object goes out of scope" You may be interested in PEP 310 (reliable acquisition/release pairs): http://www.python.org/peps/pep-0310.html (Although if that idea gets ado

Re: Closing files

2004-11-29 Thread Daniel Dittmar
Timo Virkkala wrote: Daniel Dittmar wrote: And then there are a lot of people who think that changing all the readlines one liner would be quite easy should the need of a Jython port arrive, so why bother about it now? The problem with this approach is, when the time for the Jython port arrives,

Re: Closing files

2004-11-29 Thread Timo Virkkala
Daniel Dittmar wrote: And then there are a lot of people who think that changing all the readlines one liner would be quite easy should the need of a Jython port arrive, so why bother about it now? The problem with this approach is, when the time for the Jython port arrives, do you remember to d

Re: Closing files

2004-11-29 Thread Daniel Dittmar
Henrik Holm wrote: I have recently started playing around with Python. Some of the things I have done have involved reading files. The way I do this is along the lines of f = file('file.txt') lines = f.readlines() f.close() I have noticed that it is possible to do this in one line: lines

Re: Closing files

2004-11-28 Thread Jerry Sievers
[EMAIL PROTECTED] (Henrik Holm) writes: [+] > I have recently started playing around with Python. Some of the things > I have done have involved reading files. The way I do this is along the > lines of > > f = file('file.txt') > lines = f.readlines() > f.close() Verbose and readable. A

Re: Closing files

2004-11-28 Thread Jp Calderone
On Sun, 28 Nov 2004 18:59:31 -0600, [EMAIL PROTECTED] (Henrik Holm) wrote: >I have recently started playing around with Python. Some of the things > I have done have involved reading files. The way I do this is along the > lines of > > [snip] http://www.google.com/search?q=site%3Amail.python.

Closing files

2004-11-28 Thread Henrik Holm
I have recently started playing around with Python. Some of the things I have done have involved reading files. The way I do this is along the lines of f = file('file.txt') lines = f.readlines() f.close() I have noticed that it is possible to do this in one line: lines = file('file.txt