Dr Dobbs "with" keyword

N

Neil Hodgson

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. The discussion of cyclic
garbage also troubles me but is not an area in which I have much
experience.

While publishing a correction in a future issue would not be very
helpful, adding a correction to online and CD-ROM versions would be. If
anyone understands the technical review process at DDJ, could they give
them a little prod.

Neil
 
G

Giovanni Bajo

Neil said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top