Dr Dobbs "with" keyword

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neil Hodgson

    #1

    Dr Dobbs "with" keyword

    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
  • Giovanni Bajo

    #2
    Re: Dr Dobbs "with&quot ; keyword

    Neil Hodgson wrote:
    [color=blue]
    > 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.[/color]

    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.m utex.lock, self.mutex.unlo ck):
    pass

    Either that, or "with" could call adapt() implicitly so I can register my
    conversion functions.
    --
    Giovanni Bajo


    Comment

    Working...