merits of Lisp vs Python
Kirk Sluder
kirk at nospam.jobsluder.net
Sun Dec 10 01:57:57 EST 2006
In article <7xfybo1dlj.fsf at ruckus.brouhaha.com>,
Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
> Kirk Sluder <kirk at nospam.jobsluder.net> writes:
> > The pythonic way to do this would be to create a class that
> > implements file-like behaviors:
....
>
> Actually the Python example can lose (e.g. leak a file descriptor
> temporarily) if output.write raises an exception (prevents
> output.close from running). For this reason Python recently
> introduced the "with" statement:
>
> with output as fileLike.open():
> output.write("Hello world\n")
>
> Here the file gets closed automatically (by running an exit method in
> the fileLike class) when the "with" block exits, whether normally or
> through an exception.
Ohhh, shiny!
More information about the Python-list
mailing list