[Tutor] How to open the closed file again?
ALAN GAULD
alan.gauld at btinternet.com
Tue Jan 5 17:52:40 CET 2010
> > 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 forgotten that the file object had a name
attribute so yes that should work.
Although personally I'd probably go with the custom fileobject
approach just for the improved readability.
Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100105/ad80b850/attachment.htm>
More information about the Tutor
mailing list