On 2/28/2012 5:12 PM, Prasad, Ramit wrote:
Craig Yoshioka wrote:
I see that there was previously a PEP to allow the with statement to skip the 
enclosing block... this was shot down, and I'm trying to think of the most 
elegant alternative. [..]

I would have really liked:
with cachingcontext(x):
    # create cached resources here
# return cached resources

Is this a common pattern? I thought the point of the context manager
was to remove create and close the resources (like with file opening).

Exactly. It is Python's version of RAII
https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

Seems slightly odd to use just for creation...
I do not see the point either.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to