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 in
On Dec 10, 11:59 am, Christian Heimes wrote:
> In Python 2.5 you have to implement your own __enter__ and __exit__
> methods if you subclass from file. The file.__exit__ function doesn't
> call f.close().
Yes, that was my problem.
--
http://mail.python.org/mailman/listinfo/python-list
Michele Simionato wrote:
> On Dec 10, 11:04 am, "Diez B. Roggisch" wrote:
>> Are you sure? For me on python2.5, it works as advertised:
>>
>> from __future__ import with_statement
>>
>> def test(outf):
>> with outf:
>> outf.write("test\n")
>> try:
>> outf.write("test\n")
>> assert False, "Not clo
Michele Simionato wrote:
> Python 2.5, but it could be an artifact of the way I am looking if a
> file is closed.
> I have subclassed the file builtin, added a .close method and it was
> not called by the
> "with" statement. This during debugging, but now I have found another
> reason to explain wh
Michele Simionato wrote:
> On Dec 10, 11:04 am, "Diez B. Roggisch" wrote:
>> Are you sure? For me on python2.5, it works as advertised:
>>
>> from __future__ import with_statement
>>
>> def test(outf):
>> with outf:
>> outf.write("test\n")
>> try:
>> outf.write("test\n")
>> assert False, "Not clo
On Dec 10, 11:04 am, "Diez B. Roggisch" wrote:
> Are you sure? For me on python2.5, it works as advertised:
>
> from __future__ import with_statement
>
> def test(outf):
> with outf:
> outf.write("test\n")
> try:
> outf.write("test\n")
> assert False, "Not closed"
>
Michele Simionato wrote:
> 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
Michele Simionato wrote:
> 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