Neil Hodgson wrote: > In the March 2005 issue of Dr Dobbs Journal there is an article > "Resource Management in Python" by Oliver Schoenborn. One paragraph > (first new paragraph, page 56) starts "Starting with Python 2.4, a new > type of expression lets you use the keyword /with/". It continues, > mentioning PEP 310 (Reliable Acquisition/Release Pairs) which is at > "Draft" status and unlikely to be accepted with the keyword "with" as > Guido wants to use that for another purpose.
Whatever keyword is chosen, I hope PEP 310 eventually hit Python, I have been awaiting it for a long time. I would also like to have a builtin resource() like this: def resource(enter_call, exit_call): class Res(object): __enter__ = lambda self: enter_call() __exit__ = lambda self: exit_call() return Res() with resource(self.mutex.lock, self.mutex.unlock): pass Either that, or "with" could call adapt() implicitly so I can register my conversion functions. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list