Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.038 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'skip': 0.04; 'cached': 0.07; 'scripts': 0.09; 'header:In-reply-to:1': 0.09; 'wrappers': 0.09; 'atomically': 0.16; 'caching': 0.16; 'confusing.': 0.16; 'non-python': 0.16; 'subject:alternative': 0.16; 'wrote:': 0.18; 'wrap': 0.18; 'previously': 0.19; 'trying': 0.21; 'appropriate': 0.22; 'feb': 0.22; 'statement': 0.23; 'pep': 0.23; 'coordinate': 0.24; 'url:mailman': 0.27; 'bit': 0.28; "i'm": 0.28; 'pm,': 0.29; 'down,': 0.30; 'subject:?': 0.31; 'url:listinfo': 0.32; "i've": 0.32; 'does': 0.32; 'there': 0.33; 'loop': 0.34; 'elegant': 0.34; 'safely': 0.34; 'to:addr:python-list': 0.35; 'url:python': 0.35; 'but': 0.37; 'subject:with': 0.37; 'received:10.0.1': 0.38; 'think': 0.38; 'abuse': 0.39; 'url:org': 0.39; "i'd": 0.39; 'called': 0.40; 'might': 0.40; 'to:addr:python.org': 0.40; 'release': 0.40; 'more': 0.61; 'here': 0.64; 'strategy': 0.64; 'experts': 0.70; 'unnecessary': 0.73; "'with'": 0.84; '2012,': 0.84; 'alternative.': 0.84; 'activity,': 0.91; 'craig': 0.91; 'inability': 0.91 MIME-version: 1.0 Content-type: text/plain; charset=windows-1252 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-1202280234 Subject: Re: alternative to with statement? From: Craig Yoshioka In-reply-to: Date: Tue, 28 Feb 2012 14:22:46 -0800 Content-transfer-encoding: quoted-printable References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330471410 news.xs4all.nl 6943 [2001:888:2000:d::a6]:58303 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:21013 It is a bit non-normal. but I think this is a good use case as I want = to create a very simple-to-use system for non-python experts to safely = wrap their CLI programs in a caching architecture... that's why I lament = the inability to not use the more streamlined 'with' syntax=96 abusing = the for loop might just be confusing. The with statement is also a good = fit because the caching strategy does have to atomically acquire, create = and release the appropriate locks. With this statement the cached CLI = wrappers can be called from simultaneously from different scripts and = still coordinate their activity, by waiting for each other to finish, = and reusing the cached results, etc. =20 On Feb 28, 2012, at 1:04 PM, 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. > The best I've found is to abuse the for notation: >=20 > for _ in cachingcontext(x): > # create cached resources here > # return cached resources >=20 > I would have really liked: >=20 > with cachingcontext(x): > # create cached resources here > # return cached resources >=20 > I'd also like to avoid the following because it is unnecessary = boilerplate: >=20 > with cachingcontext(x) as skip: > if not skip: > # create cached resources here > # return cached resources >=20 >=20 >=20 > --=20 > http://mail.python.org/mailman/listinfo/python-list