"file" does not work with the "with" statement!
Michele Simionato
michele.simionato at gmail.com
Thu Dec 10 04:13:47 EST 2009
I have just discovered that the syntax
with file(name, 'w') as f:
do_something(f)
does not close the file at the end of the with statement! On the
contrary
with open(name, 'w') as f:
do_something(f)
works fine. The docs say "When opening a file, it’s preferable to use
open() instead of invoking this constructor directly." but perhaps
they should mention why :(
More information about the Python-list
mailing list