with statement and standard library

nobrowser nobrowser at gmail.com
Fri Feb 19 02:18:20 EST 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.  Maybe it
is the case that some of these classes have with statement support
already but I don't know it?  If so, how can I know (without asking
here each time, LOL)?  If not, is there work being done on that?

I am interested in this question mostly in the context of Python 2.6.

Many thanks.



More information about the Python-list mailing list