Question about import and sys.path
rw at smsnet.pl
Wed Nov 29 09:03:29 CET 2006
Frank Millman wrote:
> One small point. The docs have the following warning -
> "Important: the caller is responsible for closing the file argument, if
> it was not None, even when an exception is raised. This is best done
> using a try ... finally statement. "
> I have added this to my code.
> I wonder if you can avoid this in 2.5 by using the 'with' statement. I
> am still using 2.4, so I cannot test. Anyway, your suggestion does
> exactly what I want, and it works perfectly.
Yes, of course. The `with` statement works exactly
as previously try...finally. I've tried it in 2.5 and it works
You have to use `from __future__ import with_statement`, though.
This statement will be always enabled in Python 2.6.
More information about the Python-list