Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python?': 0.05; 'wrapper': 0.07; 'subject:Function': 0.09; 'underlying': 0.09; 'def': 0.15; 'bit.': 0.16; 'closures': 0.16; 'example?': 0.16; 'exists?': 0.16; 'foo(10,': 0.16; 'functools': 0.16; 'lambda': 0.16; 'parks': 0.16; 'read-only.': 0.16; 'thing?': 0.16; 'travis': 0.16; 'cc:addr :python-list': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'function': 0.27; 'import': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'disappointed': 0.30; 'someone': 0.34; 'quite': 0.34; 'received:209.85.161': 0.35; 'explain': 0.36; 'limitation': 0.37; 'partial': 0.37; 'something': 0.37; 'members': 0.37; 'easiest': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'why': 0.39; 'day': 0.69; 'august': 0.70; 'realized': 0.73; '10)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=HG8US+sYE2HZ0rFoJ3VCrWjmoGptu/EzfdDGgibFKtY=; b=TGhYu+29d8R6IlGA6JsO4eXKLsympJ6ZAMXH7dpOYp6F24onmWhXZzkgJYA7c403GE +KbCmfGPbnpVigcc6Ssqx5970iB3QVQlmOspt+gzL44rr/o1I1hbDjeAbWEqV/ZRoei6 +J8vTQo8YMwRmHja4ABaS7I66s3xkfbMu9ar0= MIME-Version: 1.0 In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Date: Wed, 31 Aug 2011 17:55:34 +0100 Subject: Re: Closures and Partial Function Application From: Arnaud Delobelle To: Travis Parks Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314809735 news.xs4all.nl 2448 [2001:888:2000:d::a6]:35355 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12500 On 31 August 2011 17:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. > > Can someone explain why this limitation exists? Secondly, since I can > cheat by wrapping the thing being closure-ified, how can I write a > simple wrapper that has all the same members as the thing (decorator), > that then applies them to the underlying thing? I don't understand. Can you give an example? > I also like partial function application. What is the easiest way of > achieving this in Python? Would it look something like this: > > def foo(x, y): > =C2=A0 =C2=A0return x + y > > xFoo =3D lambda y: foo(10, y) from functools import partial foo10 =3D partial(foo, 10) HTH Arnaud