"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
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
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
> > 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
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
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
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
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
> 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)
>>
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
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
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
"朱淳" 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
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
14 matches
Mail list logo