Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21006

alternative to with statement?

From Craig Yoshioka <craigyk@me.com>
Subject alternative to with statement?
Date 2012-02-28 13:04 -0800
Newsgroups comp.lang.python
Message-ID <mailman.263.1330466725.3037.python-list@python.org> (permalink)

Show all headers | View raw


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.
The best I've found is to abuse the for notation:

for _ in cachingcontext(x):
    # create cached resources here
# return cached resources

I would have really liked:

with cachingcontext(x):
    # create cached resources here
# return cached resources

I'd also like to avoid the following because it is unnecessary boilerplate:

with cachingcontext(x) as skip:
    if not skip:
         # create cached resources here
# return cached resources


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

alternative to with statement? Craig Yoshioka <craigyk@me.com> - 2012-02-28 13:04 -0800

csiph-web