Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18660
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
|---|---|
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Nested Function Question |
| Date | Sat, 7 Jan 2012 20:43:48 -0800 (PST) |
| Organization | http://groups.google.com |
| Lines | 39 |
| Message-ID | <33260053.1203.1325997828352.JavaMail.geo-discussion-forums@prak33> (permalink) |
| References | <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> |
| Reply-To | comp.lang.python@googlegroups.com |
| NNTP-Posting-Host | 1.168.129.93 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1325997829 29204 127.0.0.1 (8 Jan 2012 04:43:49 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Sun, 8 Jan 2012 04:43:49 +0000 (UTC) |
| In-Reply-To | <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=1.168.129.93; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18660 |
Show key headers only | View raw
GZ於 2012年1月7日星期六UTC+8上午5時46分16秒寫道: > 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. > > Thanks, > GZ This is used to produce a new function with some default parameters fixed of an old function that requires many parameters in the caller part.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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