with statement and standard library
nagle at animats.com
Mon Feb 22 00:21:38 CET 2010
> 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.
More information about the Python-list