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


Groups > comp.lang.python > #18647

Re: Nested Function Question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <drobinow@gmail.com>
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; 'args': 0.05; 'args,': 0.09; 'func': 0.09; 'garbage': 0.09; 'referencing': 0.09; 'subject:Function': 0.09; 'def': 0.13; 'stored': 0.13; '*args,': 0.16; '\xa0def': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'arguments': 0.18; 'jan': 0.19; 'seems': 0.20; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'holds': 0.21; 'subject:Question': 0.21; 'header:In-Reply-To:1': 0.22; 'code': 0.25; 'function': 0.27; 'cc:addr:gmail.com': 0.28; 'tend': 0.28; 'message-id:@mail.gmail.com': 0.28; 'partial': 0.29; 'toward': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'lines': 0.30; 'kelly': 0.30; 'hi,': 0.32; 'skip:\xa0 30': 0.32; 'object': 0.33; 'fri,': 0.34; '8bit%:3': 0.34; 'received:74.125.82': 0.35; 'something': 0.35; 'cc:2**1': 0.36; 'later,': 0.37; 'but': 0.37; 'passed': 0.37; 'reference': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'references': 0.38; 'skip:\xa0 10': 0.39; 'should': 0.39; 'being': 0.39; 'why': 0.39; '8bit%:8': 0.40; 'below': 0.63; '2012': 0.67; 'collection,': 0.84; 'needed:': 0.84; 'skip:d 50': 0.93
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=OfmoaMssRtWugwdqJ2b20ybFAMRjO1dziUBTehZqNMw=; b=vsjPY0TZ0jjKRdrDoUOfTHUv4SsZild/xeYeQvrr+Hxgl29G2/kUNbz6cefMXeM+Hm WYHv5okX7Cw8HKXh9Dj904MLE5r1fWPKjL1/7ATuCtq6EJDHxU+dTtxHzRWcuTT4AcO0 LSvl6nbQa+f4aeXhNYETNmca6zfbmIIBshKcc=
MIME-Version 1.0
In-Reply-To <CALwzidneNuQAD6i6rGrVxds482YckmmEY+HHR8q_HLKJOdheOA@mail.gmail.com>
References <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> <CALwzidneNuQAD6i6rGrVxds482YckmmEY+HHR8q_HLKJOdheOA@mail.gmail.com>
Date Sat, 7 Jan 2012 10:18:15 -0500
Subject Re: Nested Function Question
From David Robinow <drobinow@gmail.com>
To Ian Kelly <ian.g.kelly@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc GZ <zyzhu2000@gmail.com>, 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 <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.4513.1325949503.27778.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325949503 news.xs4all.nl 6918 [2001:888:2000:d::a6]:40435
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18647

Show key headers only | View raw


On Fri, Jan 6, 2012 at 5:04 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Fri, Jan 6, 2012 at 2:46 PM, GZ <zyzhu2000@gmail.com> wrote:
>> Hi,
>>
>> I am reading the documentation of functools.partial (http://
>> docs.python.org/library/functools.html#functools.partial) and found
>> the following 'reference implementation' of functools.partial.
>>
>> def partial(func, *args, **keywords):
>>    def newfunc(*fargs, **fkeywords):
>>        newkeywords = keywords.copy()
>>        newkeywords.update(fkeywords)
>>        return func(*(args + fargs), **newkeywords)
>>    newfunc.func = func
>>    newfunc.args = args
>>    newfunc.keywords = keywords
>>    return newfunc
>>
>> I don't understand why the below 3 lines are needed:
>>
>>    newfunc.func = func
>>    newfunc.args = args
>>    newfunc.keywords = keywords
>>
>>
>> It is as if they are trying to prevent garbage collection, but I don't
>> get why it is needed. As long as something holds reference to newfunc,
>> because it in turn references keywords and args, nothing will be
>> freed. If nothing is referencing newfunc, then everything should be
>> freed.
>
> They exist for introspection.  The partial object has to store the
> function and arguments it was passed so that it can call it later, so
> as long as they're being stored anyway, why not make them visible?
I tend toward the minimalist end of the spectrum when it comes to code
commenting, but it seems to me this would be a good place for a few
words of explanation.

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


Thread

Nested Function Question GZ <zyzhu2000@gmail.com> - 2012-01-06 13:46 -0800
  Re: Nested Function Question Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 15:04 -0700
  Re: Nested Function Question David Robinow <drobinow@gmail.com> - 2012-01-07 10:18 -0500
  Re: Nested Function Question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-07 20:43 -0800

csiph-web