On 2007-08-12, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
OK, I've thought about this some more and I think the source
of my confusion was I thought assignment in Python meant
binding a name to something, not mutating an object. But in
the case of
Neil Cerutti [EMAIL PROTECTED] wrote:
...
Then we get into unpacking assignments and augmented
assignments, but I don't really want to write two more pages
worth of summary...;-).
Thanks very much for taking the time to help clear up my
erroneous model of assignment in Python. I'd
Aahz wrote:
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Because of this, a Google search for
name surname python
may sometimes help; when you get 116,000 hits, as for Steve Holden
python, that may be a reasonable indication that the poster is one of
the world's
On Aug 13, 2:22 pm, Ricardo Aráoz [EMAIL PROTECTED] wrote:
Aahz wrote:
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Because of this, a Google search for
name surname python
may sometimes help; when you get 116,000 hits, as for Steve Holden
python, that may
[EMAIL PROTECTED] wrote:
On Aug 13, 2:22 pm, Ricardo Aráoz [EMAIL PROTECTED] wrote:
Aahz wrote:
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Because of this, a Google search for
name surname python
may sometimes help; when you get 116,000 hits, as for Steve Holden
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric types
6.3.1 Augmented assignment statements
The former refers to augmented
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Because of this, a Google search for
name surname python
may sometimes help; when you get 116,000 hits, as for Steve Holden
python, that may be a reasonable indication that the poster is one of
the world's Python Gurus (in
In article [EMAIL PROTECTED],
Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric types
6.3.1
Aahz wrote:
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Because of this, a Google search for
name surname python
may sometimes help; when you get 116,000 hits, as for Steve Holden
python, that may be a reasonable indication that the poster is one of
the world's
Aahz schreef:
In article [EMAIL PROTECTED],
Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric
In article [EMAIL PROTECTED],
Roel Schroeven [EMAIL PROTECTED] wrote:
Aahz schreef:
Although Alex is essentially correct, the situation is a bit more complex
and you are correct that augmented assignment allows the object to decide
whether to mutate in place. However, the critical part of
Aahz schreef:
def foo(bar): bar[0] += ['zap']
...
import dis
dis.dis(foo)
1 0 LOAD_FAST0 (bar)
3 LOAD_CONST 1 (0)
6 DUP_TOPX 2
9 BINARY_SUBSCR
10 LOAD_CONST
Aahz wrote:
tup=([],)
tup[0] += ['zap']
Traceback (most recent call last):
File stdin, line 1, in module
TypeError: 'tuple' object does not support item assignment
snip
Obviously, you can easily work around it:
t = ([],)
l = t[0]
l += ['foo']
t
(['foo'],)
This is quite
OKB (not okblacke) schreef:
Aahz wrote:
tup=([],)
tup[0] += ['zap']
Traceback (most recent call last):
File stdin, line 1, in module
TypeError: 'tuple' object does not support item assignment
snip
Obviously, you can easily work around it:
t = ([],)
l = t[0]
l += ['foo']
t
Neil Cerutti wrote:
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric types
6.3.1 Augmented assignment statements
The former refers to
Gregory D. Weber schreef:
Neil Cerutti wrote:
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric types
6.3.1 Augmented assignment
In article [EMAIL PROTECTED],
OKB (not okblacke) [EMAIL PROTECTED] wrote:
This sentence is phrased as though it is the whole story, but it
isn't, because the operation might not in fact wind up being an
assignment. Shouldn't there be an except see below or something
there, to alert the
In article [EMAIL PROTECTED],
Roel Schroeven [EMAIL PROTECTED] wrote:
I used to interpret the target in 'The target is only evaluated once'
more like an L-value in C/C++. That's not correct, of course, but I
didn't understand exactly how wrong it was until now.
It's true almost everywhere
On 8/11/07, Gregory D. Weber [EMAIL PROTECTED] wrote:
I too thought += was an assignment. And it bit me very painfully a few weeks
ago.
If it's an assignment, then wouldn't x += y mean the same thing as x = x +
y?
If so, why does an assignment to variable a, below, have the *side effect*
On 2007-08-11, Alex Martelli [EMAIL PROTECTED] wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about
the terminology.
3.4.7 Emulating numeric types
6.3.1 Augmented assignment statements
The former refers to augmented
Neil Cerutti [EMAIL PROTECTED] wrote:
...
OK, I've thought about this some more and I think the source of
my confusion was I thought assignment in Python meant binding a
name to something, not mutating an object. But in the case of
augmented assignment, assignment no longer means that?
greg [EMAIL PROTECTED] wrote:
Steve Holden wrote:
For some reason your reply got right up my nose,
I'm sorry about that. Sometimes it's hard to judge the
level of experience with Python that a poster has. In
Because of this, a Google search for
name surname python
may sometimes
Neil Cerutti [EMAIL PROTECTED] wrote:
...
The Python Language Reference seems a little confused about the
terminology.
3.4.7 Emulating numeric types
6.3.1 Augmented assignment statements
The former refers to augmented arithmetic operations, which I
think is a nice terminology,
Lee Fleming wrote:
Hello,
I have a simple question. Say you have the following function:
def f(x, y = []):
...
But this, the code that fixes the list accumulation confounds me:
def f(x, y=None):
if y is None: y = []
...
In other words, what's going on here? How is it that y
On 2007-08-09, Magnus Lycka [EMAIL PROTECTED] wrote:
It's all a matter of understanding that all the juicy bits in
the Python data model is in the actual values or objects.
That's the stuff with type safety, a location in memory,
qualities such as mutability etc. A variable is basically
just
greg wrote:
Steve Holden wrote:
OK. The difference is that [] is a mutable value, while None is
immutable.
No, it's not. It has nothing to do with mutability
vs immutability.
I beg to differ. That has everything to do with it.
The difference is that in the first version the
expression
On Wed, 2007-08-08 at 08:52 -0400, Steve Holden wrote:
While it's correct that rebinding y will usually cause it to reference a
different object, this need not be true of assignment. The augmented
assignment operations do no necessarily rebind their left-hand operand -
that depends on the
Carsten Haese wrote:
On Wed, 2007-08-08 at 08:52 -0400, Steve Holden wrote:
[...]
The problem is your ambiguous use of the word assignment. In the sense
of the Language Reference, any assignment to y is a simple assignment
that always modifies a namespace and never modifies an object. In
On 2007-08-08, Steve Holden [EMAIL PROTECTED] wrote:
Carsten Haese wrote:
On Wed, 2007-08-08 at 08:52 -0400, Steve Holden wrote:
[...]
The problem is your ambiguous use of the word assignment. In
the sense of the Language Reference, any assignment to y is
a simple assignment that always
Steve Holden wrote:
For some reason your reply got right up my nose,
I'm sorry about that. Sometimes it's hard to judge the
level of experience with Python that a poster has. In
discussions about this particular topic, often it turns
out that the person is a newcomer to Python who is
using the
greg wrote:
Steve Holden wrote:
For some reason your reply got right up my nose,
I'm sorry about that. Sometimes it's hard to judge the
level of experience with Python that a poster has. In
discussions about this particular topic, often it turns
out that the person is a newcomer to
Lee Fleming wrote:
Thanks for all the help, everyone. I guess I was confused with default
arguments that were mutable and immutable. I will continue to look
over these posts until I understand what is happening.
I cannot believe the number of helpful responses I got!
Apparently he didn't
On 8/7/07, Ricardo Aráoz [EMAIL PROTECTED] wrote:
Lee Fleming wrote:
Thanks for all the help, everyone. I guess I was confused with default
arguments that were mutable and immutable. I will continue to look
over these posts until I understand what is happening.
I cannot believe the
Ricardo Aráoz wrote:
Lee Fleming wrote:
Thanks for all the help, everyone. I guess I was confused with default
arguments that were mutable and immutable. I will continue to look
over these posts until I understand what is happening.
I cannot believe the number of helpful responses I got!
Steve Holden wrote:
OK. The difference is that [] is a mutable value, while None is
immutable.
No, it's not. It has nothing to do with mutability
vs immutability.
The difference is that in the first version the
expression [] is evaluated only *once*, when the
function is defined. Therefore
Hello,
I have a simple question. Say you have the following function:
def f(x, y = []):
y.append(x)
return y
print f(23) # prints [23]
print f(42) # prints [23, 42]
As far as I understand, the default value y, an empty list, is created
when the def statement evaluates. With this
On Sun, 05 Aug 2007 23:50:24 -0700, Lee Fleming wrote:
But this, the code that fixes the list accumulation confounds me:
def f(x, y=None):
if y is None: y = []
y.append(x)
return y
print f(23) # prints [23]
print f(42) # prints [42]
Why didn't the second call to f,
On Sun, 05 Aug 2007 23:50:24 -0700, Lee Fleming wrote:
Hello,
I have a simple question. Say you have the following function:
def f(x, y = []):
y.append(x)
return y
print f(23) # prints [23]
print f(42) # prints [23, 42]
As far as I understand, the default value y, an empty
Stargaming [EMAIL PROTECTED] wrote in news:46b6df49$0$26165
[EMAIL PROTECTED]:
On Sun, 05 Aug 2007 23:50:24 -0700, Lee Fleming wrote:
Hello,
I have a simple question. Say you have the following function:
def f(x, y = []):
y.append(x)
return y
print f(23) # prints [23]
print
On 2007-08-06, Lee Fleming [EMAIL PROTECTED] wrote:
I have a simple question. Say you have the following function:
def f(x, y = []):
y.append(x)
return y
print f(23) # prints [23]
print f(42) # prints [23, 42]
def f(x, y=None):
if y is None: y = []
y.append(x)
On 2007-08-06, Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-08-06, Lee Fleming [EMAIL PROTECTED] wrote:
def f(x, y=None):
if y is None: y = []
y.append(x)
return y
f(f(23))
[23, 42]
Sorry. That should've been:
f(42, f(23))
[23, 42]
--
Neil Cerutti
Scouts are saving
On Mon, 06 Aug 2007 11:13:45 +, Alex Popescu wrote:
Stargaming [EMAIL PROTECTED] wrote in news:46b6df49$0$26165
[EMAIL PROTECTED]:
[snip]
You're just unluckily shadowing the name `y` in the local scope of
your
function. Your code snippet could be rewritten as::
def f(x, y=None):
On Aug 6, 6:25 am, Neil Cerutti [EMAIL PROTECTED] wrote:
Because when the function is called, the line
if y is None: y = []
is executed, binding a brand new empty list to y. This
rebinding happens every time the function is called, unless you
provide an argument for y that is not None.
From: Lee Fleming
On Aug 6, 6:25 am, Neil Cerutti [EMAIL PROTECTED] wrote:
Because when the function is called, the line
if y is None: y = []
is executed, binding a brand new empty list to y. This
rebinding happens every time the function is called, unless you
provide an
On Aug 6, 12:30 pm, Hamilton, William [EMAIL PROTECTED] wrote:
When you call f(23), the variable y within it gets created and points at
None. When f(23) exits, the y that it created gets destroyed. (Well,
goes out of scope, but even if it's not garbage collected it won't ever
come back into
On 2007-08-06, Lee Fleming [EMAIL PROTECTED] wrote:
On Aug 6, 6:25 am, Neil Cerutti [EMAIL PROTECTED] wrote:
Because when the function is called, the line
if y is None: y = []
is executed, binding a brand new empty list to y. This
rebinding happens every time the function is called,
On 2007-08-06, Lee Fleming [EMAIL PROTECTED] wrote:
On Aug 6, 12:30 pm, Hamilton, William [EMAIL PROTECTED] wrote:
When you call f(23), the variable y within it gets created and points at
None. When f(23) exits, the y that it created gets destroyed. (Well,
goes out of scope, but even if
On Mon, 06 Aug 2007 10:51:20 -0700, Lee Fleming wrote:
why isn't the y in def f (x, y = []): something
garbage-collected?
`y` is a name. Only objects are garbage collected. There is no `y` in
that ``def`` in the sense that a local name `y` exists when the ``def`` is
executed. The line just
From: Lee Fleming
On Aug 6, 12:30 pm, Hamilton, William [EMAIL PROTECTED] wrote:
When you call f(23), the variable y within it gets created and
points at
None. When f(23) exits, the y that it created gets destroyed.
(Well,
goes out of scope, but even if it's not garbage collected it
Thanks for all the help, everyone. I guess I was confused with default
arguments that were mutable and immutable. I will continue to look
over these posts until I understand what is happening.
I cannot believe the number of helpful responses I got!
--
Lee Fleming wrote:
On Aug 6, 6:25 am, Neil Cerutti [EMAIL PROTECTED] wrote:
Because when the function is called, the line
if y is None: y = []
is executed, binding a brand new empty list to y. This
rebinding happens every time the function is called, unless you
provide an
On Aug 6, 1:26 pm, Steve Holden [EMAIL PROTECTED] wrote:
Lee Fleming wrote:
On Aug 6, 6:25 am, Neil Cerutti [EMAIL PROTECTED] wrote:
Because when the function is called, the line
if y is None: y = []
is executed, binding a brand new empty list to y. This
rebinding happens every
Marc 'BlackJack' Rintsch wrote:
On Mon, 06 Aug 2007 10:51:20 -0700, Lee Fleming wrote:
why isn't the y in def f (x, y = []): something
garbage-collected?
`y` is a name. Only objects are garbage collected. There is no `y` in
that ``def`` in the sense that a local name `y` exists when the
53 matches
Mail list logo