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


Groups > comp.lang.python > #21006

alternative to with statement?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <craigyk@me.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.064
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'skip': 0.04; 'cached': 0.07; 'subject:alternative': 0.16; 'previously': 0.19; 'trying': 0.21; 'statement': 0.23; 'pep': 0.23; "i'm": 0.28; 'down,': 0.30; 'subject:?': 0.31; "i've": 0.32; 'there': 0.33; 'elegant': 0.34; 'to:addr:python-list': 0.35; 'charset:us-ascii': 0.37; 'subject:with': 0.37; 'received:10.0.1': 0.38; 'think': 0.38; 'abuse': 0.39; "i'd": 0.39; 'to:addr:python.org': 0.40; 'here': 0.64; 'unnecessary': 0.73; 'alternative.': 0.84
MIME-version 1.0
Content-transfer-encoding 7BIT
Content-type text/plain; CHARSET=US-ASCII
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:5.6.7498,1.0.260,0.0.0000 definitions=2012-02-28_08:2012-02-28, 2012-02-28, 1970-01-01 signatures=0
X-Proofpoint-Spam-Details rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1012030000 definitions=main-1202280211
From Craig Yoshioka <craigyk@me.com>
Subject alternative to with statement?
Date Tue, 28 Feb 2012 13:04:59 -0800
To python-list@python.org
X-Mailer Apple Mail (2.1257)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.263.1330466725.3037.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330466725 news.xs4all.nl 6945 [2001:888:2000:d::a6]:49584
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:21006

Show key headers only | 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