By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,594 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,594 IT Pros & Developers. It's quick & easy.

Dr Dobbs "with" keyword

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.