with statement and standard library

John Nagle nagle at animats.com
Sun Feb 21 18:21:38 EST 2010


nobrowser wrote:
> Hi.  The with statement is certainly nifty.  The trouble is, the
> *only* two documented examples how it can be used with the library
> classes are file objects (which I use all the time) and thread locks
> which I almost never use.  Yet there are many, many classes in the
> library whose use would be more elegant and readable if the with
> statement could be employed.  Start with the connection objects in
> httplib and you can probably come up with 10 others easily. 

    "with" is important for locks because it matters when they're
released.  It's not as important if release is just resource
recovery.  Reference counting will recover most objects when they
go out of scope anyway.

    Don't get carried away just because a new feature is available.

				John Nagle



More information about the Python-list mailing list