Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45617
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ned@nedbatchelder.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'assignment': 0.07; 'subject:help': 0.08; 'cc:addr:python-list': 0.11; 'def': 0.12; 'assignments': 0.16; 'fancy': 0.16; "function's": 0.16; 'lambda': 0.16; 'rebound': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'referencing': 0.16; 'statement.': 0.16; 'wrote:': 0.18; 'skip:p 40': 0.19; 'code,': 0.22; '(in': 0.22; 'previously': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'equivalent': 0.26; 'references': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'reader': 0.33; 'comment': 0.34; 'subject:with': 0.35; 'but': 0.35; 'really': 0.36; 'next': 0.36; 'whatever': 0.38; 'skip:p 20': 0.39; 'even': 0.60; 'new': 0.61; "you're": 0.61; 'guarantee': 0.63; 'name': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'side': 0.67; 'default': 0.69; 'fact,': 0.69; 'hand': 0.80; 'as:': 0.81; 'ambiguous': 0.84 |
| Date | Mon, 20 May 2013 06:46:38 -0400 |
| From | Ned Batchelder <ned@nedbatchelder.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | Chris Angelico <rosuav@gmail.com> |
| Subject | Re: Please help with Threading |
| References | <CAPTjJmoxaieL-kwTfuHBV=jDeLpLF2=W8mzx7sv=83MwTDGZQw@mail.gmail.com> <20130520095419.GA14050@cskk.homeip.net> <CAPTjJmrEW5x0V=yju-R820Bume81HMNEHhauK0O4S6PB7mNO=A@mail.gmail.com> |
| In-Reply-To | <CAPTjJmrEW5x0V=yju-R820Bume81HMNEHhauK0O4S6PB7mNO=A@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.1886.1369046808.3114.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369046808 news.xs4all.nl 15986 [2001:888:2000:d::a6]:59952 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45617 |
Show key headers only | View raw
On 5/20/2013 6:09 AM, Chris Angelico wrote:
> Referencing a function's own name in a default has to have one of
> these interpretations:
>
> 1) It's a self-reference, which can be used to guarantee recursion
> even if the name is rebound
> 2) It references whatever previously held that name before this def statement.
The meaning must be #2. A def statement is nothing more than a fancy
assignment statement. This:
def foo(a):
return a + 1
is really just the same as:
foo = lambda a: a+1
(in fact, they compile to identical bytecode). More complex def's don't
have equivalent lambdas, but are still assignments to the name of the
function. So your "apparently recursive" print function is no more
ambiguous "x = x + 1". The x on the right hand side is the old value of
x, the x on the left hand side will be the new value of x.
# Each of these updates a name
x = x + 1
def print(*args,print=print,lock=Lock(),**kwargs):
with lock:
print(*args,**kwargs)
Of course, if you're going to use that code, a comment might be in order
to help the next reader through the trickiness...
--Ned.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Please help with Threading Ned Batchelder <ned@nedbatchelder.com> - 2013-05-20 06:46 -0400
csiph-web