[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
" " python
may sometimes help; when you get 116,000 hits, as f
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
>
> >> " " python
>
> >> may sometimes help; when you get 116,000 hits, as for "Steve Holden"
> >> p
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Alex Martelli <[EMAIL PROTECTED]> wrote:
>> Because of this, a Google search for
>>
>> " " 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
>> t
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 Pytho
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
>> th
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?
> 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 forme
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 *
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 everywh
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
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
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
OKB (not okblacke) schreef:
> Aahz wrote:
>
>>> tup=([],)
>>> tup[0] += ['zap']
Traceback (most recent call last):
File "", line 1, in
TypeError: 'tuple' object does not support item assignment
>
>> Obviously, you can easily work around it:
>>
> t = ([],)
> l = t
Aahz wrote:
>> tup=([],)
>> tup[0] += ['zap']
>>> Traceback (most recent call last):
>>> File "", line 1, in
>>> TypeError: 'tuple' object does not support item assignment
> Obviously, you can easily work around it:
>
t = ([],)
l = t[0]
l += ['foo']
t
> (['foo'],)
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_
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 critic
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.
>>
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Alex Martelli <[EMAIL PROTECTED]> wrote:
>> Because of this, a Google search for
>>
>> " " 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
>> t
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 nume
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
>
>Because of this, a Google search for
>
> " " 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 (
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
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 termi
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
" " python
may sometimes help;
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
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
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
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
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 t
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
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 th
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
>
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 t
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
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 beli
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 di
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
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
> > "rebindi
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
> pro
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!
--
http://mail.python.org/mailman/listinfo/pyth
> 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 collec
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
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
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 funct
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 ba
> 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
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 Non
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::
>>
>> de
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 Ceru
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.app
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) #
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
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
52 matches
Mail list logo