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.keys():
        if files[f] is not None:
            continue
        files[f] = open(f)

def closeFiles():
    for f in files.keys():
        if files[f] is None:
            continue
        files[f].close()
        files[f] = None

Although you'll probably want to refactor this into an object.


Cheers,

Alan Plum

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to