Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45617 > unrolled thread
| Started by | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| First post | 2013-05-20 06:46 -0400 |
| Last post | 2013-05-20 06:46 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Please help with Threading Ned Batchelder <ned@nedbatchelder.com> - 2013-05-20 06:46 -0400
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-05-20 06:46 -0400 |
| Subject | Re: Please help with Threading |
| Message-ID | <mailman.1886.1369046808.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web