Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'context': 0.04; 'wed,': 0.04; 'python': 0.07; 'malloc': 0.09; 'to:name:python list': 0.09; 'pm,': 0.11; 'slightly': 0.12; 'def': 0.13; 'wrote:': 0.14; '"with"': 0.16; 'except:': 0.16; 'python!': 0.16; '\xc2\xa0if': 0.16; 'discussion': 0.20; 'header:In-Reply-To:1': 0.22; 'subject: -- ': 0.25; 'statement': 0.26; "i'm": 0.26; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; 'hey': 0.29; 'probably': 0.30; 'skip:\xc2 20': 0.31; 'solved': 0.31; 'perhaps': 0.32; 'to:addr :python-list': 0.32; 'done': 0.32; 'someone': 0.33; 'try:': 0.35; 'apr': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; '8bit%:8': 0.39; "it's": 0.40; 'header:Received:5': 0.40; '13,': 0.60; '8bit%:11': 0.60; '2011': 0.62; 'received:74.125.83': 0.69; 'skip:\xc2 10': 0.83; '1:00': 0.84; 'here!': 0.84 MIME-Version: 1.0 In-Reply-To: References: <8abff237-5ccd-4eb6-85c8-cdc9e87520b7@bl1g2000vbb.googlegroups.com> <87k4eze4dl.fsf@mithlond.arda> <4DA4DB0F.8040509@stoneleaf.us> <1302650129.8890.0.camel@localhost.localdomain> <4da4e856$0$29986$c3e8da3$5496439d@news.astraweb.com> <4DA50D89.3090706@stoneleaf.us> From: James Mills Date: Wed, 13 Apr 2011 13:28:35 +1000 Subject: Re: Feature suggestion -- return if true To: python list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 30 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302665337 news.xs4all.nl 81481 [::ffff:82.94.164.166]:55373 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3113 On Wed, Apr 13, 2011 at 1:00 PM, Chris Angelico wrote: > def foo(param): > =C2=A0 =C2=A0resource=3Dmalloc(50000) # Shtarker, zis is Python! We don't= malloc here! > =C2=A0 =C2=A0if not resource: return 0 > =C2=A0 =C2=A0resource[param]=3D5 > =C2=A0 =C2=A0del resource > =C2=A0 =C2=A0return 1 In Python this can probably be done and perhaps is slightly more readble with the "with" statement and a context manager: def foo(param): try: with ResourceAllocator(50000) as resource: resource[param] =3D 5 return 1 except: return 0 Now I know I'm only adding to the discussion (argument) but hey it's all in good fun until someone looses an eyeball! cheers James --=20 -- James Mills -- -- "Problems are solved by method"