B
BAnderton
Greetings from beautiful Tucson, Arizona.
Question: Is there a way in Python to determine what all file
identifiers have been opened by Python, and to close them all?
Why I ask: I learned Python after cutting my programming teeth on
Matlab, where you get a list of all open file identifiers (that is,
those opened from a particular Matlab session) with "fopen('all')" and
close them with "fclose('all')". In my 4 years of experience with
Python, I haven't yet come across an equivalent means of doing this in
Python. I understand that this problem can be prevented by making
sure a "fid.close()" exists for every "open"; I need this however for
a file-permissions troubleshooting problem.
Extra info on this specific problem: In my program, python (through
subprocess) launched a text editor on a text file, and I can't seem to
save the text file through that editor (I get a "this document is in
use by another application and cannot be accessed" error from the
editor [wordpad on winXp]). The text file in question is modified by
my program prior to its loading into the launched editor. Although I
can't find unmatched "open" and "fid.close()" statements, I'd like to
implement a check for open file identifiers before launching the
editor.
Thanks very much in advance for your time and any help you can provide.
Question: Is there a way in Python to determine what all file
identifiers have been opened by Python, and to close them all?
Why I ask: I learned Python after cutting my programming teeth on
Matlab, where you get a list of all open file identifiers (that is,
those opened from a particular Matlab session) with "fopen('all')" and
close them with "fclose('all')". In my 4 years of experience with
Python, I haven't yet come across an equivalent means of doing this in
Python. I understand that this problem can be prevented by making
sure a "fid.close()" exists for every "open"; I need this however for
a file-permissions troubleshooting problem.
Extra info on this specific problem: In my program, python (through
subprocess) launched a text editor on a text file, and I can't seem to
save the text file through that editor (I get a "this document is in
use by another application and cannot be accessed" error from the
editor [wordpad on winXp]). The text file in question is modified by
my program prior to its loading into the launched editor. Although I
can't find unmatched "open" and "fid.close()" statements, I'd like to
implement a check for open file identifiers before launching the
editor.
Thanks very much in advance for your time and any help you can provide.