Steve Holden <[EMAIL PROTECTED]> wrote:
>> As a matter of interest do PyLint or PyChecker check for this situation
>> (chained assignment where the target of an assignment is also a
>> subexpression of a later assignment)?
>>
> Where's the published syntax for chained assignment?
http://docs.p
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| Terry Reedy wrote:
| > The assignment order is specified in the language reference.
|
| Where? I'm looking at
|
| http://docs.python.org/ref/assignment.html
|
| right now.
The first line of the syntax grammar is:
assi
Actually, after studying this a bit more:
http://docs.python.org/ref/assignment.html
I guess that makes sense. Sorry if I muddied the water for anyone else in my
boat:
n1 = n1.next = n2
The first thing that happens is the expression list is evaluated which is
the thing on the far right, n2. That
"Virgil Dupras" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > class Node:
> > > ... pass
> > > ...
> > node = Node()
> > nextnode = Node()
> > backup_node = node
> > node = node.next = nextnode
> > node.next is node
> > > True
> > hasattr(ba
Mark T wrote:
>
> "Alex Martelli" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>> John Nagle <[EMAIL PROTECTED]> wrote:
>>
>>> Marcin Ciura wrote:
>>>
>>> > Neither would I. I must have expressed myself not clearly enough.
>>> > Currently
>>> > x = y = z
>>> > is roughly equiv
John Nagle wrote:
>
> That's fascinating. Is that a documented feature of the language,
> or a quirk of the CPython interpreter?
>
Its a documented feature of the language. From the Reference Manual:
"An assignment statement evaluates the expression list (remember that
this can be a single ex
Steve Holden <[EMAIL PROTECTED]> wrote:
> In other words,
>
> assignment_stmt ::= (target_list "=") expression_list |
> (target_list "=") assignment_stmt
>
> and
>
> assignment_stmt ::= (target_list "=") assignment_stmt |
>
Duncan Booth wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote:
>
>>> As a matter of interest do PyLint or PyChecker check for this situation
>>> (chained assignment where the target of an assignment is also a
>>> subexpression of a later assignment)?
>>>
>> Where's the published syntax for chaine
Duncan Booth wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote:
>
>> Help me out here. It looks as though the real syntax should
>> be something like
>>
>> assignment_stmt ::= (target_list "=")+ expression_list |
>> (target_list "=")+ assignment_stmt
>
Steve Holden <[EMAIL PROTECTED]> wrote:
> Help me out here. It looks as though the real syntax should
> be something like
>
> assignment_stmt ::= (target_list "=")+ expression_list |
> (target_list "=")+ assignment_stmt
That is precisely the point. I
Duncan Booth wrote:
> "Virgil Dupras" <[EMAIL PROTECTED]> wrote:
>
>> I think I see what Marcin means. The 'node' is changed too fast in the
>> chain, and next is assigned to 'nextnode' instead of being assigned to
>> node.
>
> I can see why Marcin was confused. Many other languages assignment is
"Virgil Dupras" <[EMAIL PROTECTED]> wrote:
> I think I see what Marcin means. The 'node' is changed too fast in the
> chain, and next is assigned to 'nextnode' instead of being assigned to
> node.
I can see why Marcin was confused. Many other languages assignment is an
expression, so a=b=c is si
Mark T wrote:
> "Alex Martelli" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> John Nagle <[EMAIL PROTECTED]> wrote:
>>
>>> Marcin Ciura wrote:
>>>
Neither would I. I must have expressed myself not clearly enough.
Currently
x = y = z
is roughly equivalent to
>
Terry Reedy wrote:
> "Mark T" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> | This is interesting:
> |
> | >>> class Test(object):
> | ... def __getattribute__(self,n):
> | ... print 'reading',n
> | ... return object.__getattribute__(self,n)
> | ... def __setattr__(se
"Mark T" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| This is interesting:
|
| >>> class Test(object):
| ... def __getattribute__(self,n):
| ... print 'reading',n
| ... return object.__getattribute__(self,n)
| ... def __setattr__(self,n,v):
| ... print 'writing',n
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> John Nagle <[EMAIL PROTECTED]> wrote:
>
>> Marcin Ciura wrote:
>>
>> > Neither would I. I must have expressed myself not clearly enough.
>> > Currently
>> > x = y = z
>> > is roughly equivalent to
>> > x = z
>> > y = z
"Marcin Ciura" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Given
> class Node(object):
> pass
>
> node = Node()
> nextnode = Node()
>
> I tried to refactor the following piece of code
> node.next = nextnode
> node = nextnode
You have an error above. The first n
Virgil Dupras wrote:
> On Mar 21, 9:24 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> Marcin Ciura wrote:
>>> Steven D'Aprano wrote:
>>> x, y, z = 1, 2, 3
>>> x = y = z
>>> x, y, z
(3, 3, 3)
I certainly wouldn't expect to get (2, 3, 3).
>>> Neither would I. I must have express
On Mar 21, 10:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Virgil Dupras wrote:
> > On Mar 21, 9:24 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> >> Marcin Ciura wrote:
> >>> Steven D'Aprano wrote:
> >>> x, y, z = 1, 2, 3
> >>> x = y = z
> >>> x, y, z
> (3, 3, 3)
> I certa
John Nagle <[EMAIL PROTECTED]> wrote:
> Marcin Ciura wrote:
>
> > Neither would I. I must have expressed myself not clearly enough.
> > Currently
> > x = y = z
> > is roughly equivalent to
> > x = z
> > y = z
> > I propose to change it to
> > y = z
> > x = z
>
> Actually, it is equivalent to
>
On Mar 21, 9:24 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Marcin Ciura wrote:
> > Steven D'Aprano wrote:
> > x, y, z = 1, 2, 3
> > x = y = z
> > x, y, z
> >> (3, 3, 3)
>
> >> I certainly wouldn't expect to get (2, 3, 3).
>
> > Neither would I. I must have expressed myself not clearl
Marcin Ciura wrote:
> Steven D'Aprano wrote:
> x, y, z = 1, 2, 3
> x = y = z
> x, y, z
>> (3, 3, 3)
>>
>> I certainly wouldn't expect to get (2, 3, 3).
>
> Neither would I. I must have expressed myself not clearly enough.
> Currently
> x = y = z
> is roughly equivalent to
> x = z
> y =
Marcin Ciura wrote:
> Neither would I. I must have expressed myself not clearly enough.
> Currently
> x = y = z
> is roughly equivalent to
> x = z
> y = z
> I propose to change it to
> y = z
> x = z
Actually, it is equivalent to
y = z
x = y
> Python performs chained assignments
"Marcin Ciura" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| Neither would I. I must have expressed myself not clearly enough.
| Currently
| x = y = z
| is roughly equivalent to
| x = z
| y = z
except that z is only evaluated once.
| I propose to change it to
| y = z
| x = z
Un
Steven D'Aprano wrote:
x, y, z = 1, 2, 3
x = y = z
x, y, z
>
> (3, 3, 3)
>
> I certainly wouldn't expect to get (2, 3, 3).
Neither would I. I must have expressed myself not clearly enough.
Currently
x = y = z
is roughly equivalent to
x = z
y = z
I propose to change it to
y = z
x = z
On Wed, 21 Mar 2007 22:53:55 +0100, Marcin Ciura wrote:
> Given
>class Node(object):
>pass
>
>node = Node()
>nextnode = Node()
>
> I tried to refactor the following piece of code
>node.next = nextnode
>node = nextnode
>
> as
>node = node.next = nextnode
>
> only
Marcin Ciura <[EMAIL PROTECTED]> writes:
>node = node.next = nextnode
>
> only to discover that Python performs chained assignments
> backwards compared to other languages, i.e. left-to-right
> instead of right-to-left.
What makes you think so?
>>> a = "foo"
>>> b = "bar"
>>> c =
Given
class Node(object):
pass
node = Node()
nextnode = Node()
I tried to refactor the following piece of code
node.next = nextnode
node = nextnode
as
node = node.next = nextnode
only to discover that Python performs chained assignments
backwards compared to other langu
28 matches
Mail list logo