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()
if __name__=="__main__":
openFiles()
print "fileList
closeFiles()
print fileList
openFiles()
print fileList
I found that after closing files some closed files were left in the
list:
open files:[<open file 'file0', mode 'a' at 0xb7be1430>, <open file 'file1',
mode 'a' at 0xb7be1480>]
close files:[<closed file 'file0', mode 'a' at 0xb7be1430>, <closed file
'file1', mode 'a' at 0xb7be1480>]
open files again:[<closed file 'file0', mode 'a' at 0xb7be1430>, <closed
file 'file1', mode 'a' at 0xb7be1480>, <open file 'file0', mode 'a' at
0xb7be14d0>, <open file 'file1', mode 'a' at 0xb7be1520>]
After I call openFiles() and closeFiles() many times, the list will
become fatter and fatter, filled with valueless closed file object. How
could I open the closed file? I can't find the way in python document.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor