Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Alan Gauld
"Luhmann" wrote When there are no more references to an open file object, will it close, or the file will just remain open, forever unreachable? Even if Python didn't close the file it would effectively be closed when the process stopped running. The OS should see to that. (If it doesn't i

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Kent Johnson
On Tue, Jan 5, 2010 at 4:06 PM, Luhmann wrote: > > When there are no more references to an open file object, will it close, or > the file will just remain open, forever unreachable? When an open file object is garbage-collected it will be closed. In current versions of CPython GC happens when th

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Luhmann
When there are no more references to an open file object, will it close, or the file will just remain open, forever unreachable? Découvrez les styles qui font sensation sur Yahoo! Québec Avatars. http://cf.avatars.yahoo.com/___ Tutor maillist

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread ALAN GAULD
> > I don't know of a way to open a closed file object, you might want > > to store the filename along with the file. Then if you discover it is > > closed you can use the name to reopen it. > >You could probably just open it again, with: > > f = open(f.name, f.mode) Ah, good point. I had forgot

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread bob gailer
It might help us help you if you tell us a bit more about what you want to accomplish. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listin

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Lie Ryan
On 1/5/2010 11:46 PM, 朱淳 wrote: I've token a dictionary to save filenames, and write it into "constant.py". And I think it's a good method to create a class as Andre wrote. Thank you all! By the way, if I close a open file object, will the closed file object still occupy the memory? Any python

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Dave Angel
Andre Engels wrote: On Tue, Jan 5, 2010 at 1:46 PM, 朱淳 wrote: I've token a dictionary to save filenames, and write it into "constant.py". And I think it's a good method to create a class as Andre wrote. Thank you all! By the way, if I close a open file object, will the closed file object st

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Andre Engels
On Tue, Jan 5, 2010 at 1:46 PM, 朱淳 wrote: > I've token a dictionary to save filenames, and write it into "constant.py". > And I think it's a good method to create a class as Andre wrote.  Thank you > all! > By the way, if I close a open file object, will the closed file object still > occupy the m

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Kent Johnson
> 2010/1/5 朱淳 : >> Hi all, >>     I put files in a list, just like this module: >> >> #! /usr/bin/python >> # -*- coding=utf-8 -*- >> >> >> fileList = [] >> >> def openFiles(): >>     for i in range(0,2): >>     fname = "file%s"%i >>     f = open(fname,"a") >>     fileList.append(f) >>

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread 朱淳
I've token a dictionary to save filenames, and write it into "constant.py". And I think it's a good method to create a class as Andre wrote. Thank you all! By the way, if I close a open file object, will the closed file object still occupy the memory ? As I saw in a list, this kind of unusable fil

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Dave Angel
Alan Gauld wrote: "朱淳" wrote fileList = [] def openFiles(): for i in range(0,2): fname = "file%s"%i f = open(fname,"a") fileList.append(f) def closeFiles(): for f in fileList: f.close() if __name__=="__main__": openFiles() print "fileList closeFiles() print fileList openFiles() print fileL

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Alan Plum
On Di, 2010-01-05 at 16:24 +0800, 朱淳 wrote: > I found that after closing files some closed files were left in the > list: Why don't you use a dictionary mapping filenames to open file objects instead? files = {'/path/to/file1': None, '/path/to/file2': None} def openFiles(): for f in files.ke

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Alan Gauld
"朱淳" wrote fileList = [] def openFiles(): for i in range(0,2): fname = "file%s"%i f = open(fname,"a") fileList.append(f) def closeFiles(): for f in fileList: f.close() if __name__=="__main__": openFiles() print "fileList closeFiles() print fileL

[Tutor] How to open the closed file again?

2010-01-05 Thread 朱淳
Hi all, I put files in a list, just like this module: #! /usr/bin/python # -*- coding=utf-8 -*- fileList = [] def openFiles(): for i in range(0,2): fname = "file%s"%i f = open(fname,"a") fileList.append(f) def closeFiles(): for f in fileList: f.close