Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16717

the deceptive continuous assignments

Date 2011-12-06 03:06 -0800
From Yingjie Lan <lanyjie@yahoo.com>
Subject the deceptive continuous assignments
Newsgroups comp.lang.python
Message-ID <mailman.3339.1323169726.27778.python-list@python.org> (permalink)

Show all headers | View raw


Hi, I just figured out this with Python3.2 IDLE:

>>> class k: pass
>>> x=k()
>>> x.thing = 1
>>> x.thing
1
>>> x = x.thing = 1
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    x = x.thing = 1
AttributeError: 'int' object has no attribute 'thing'
>>> x
1
>>>

================
when I do x=x.thing=1, I thought it would
be like in C, 1 is first assigned to x.thing,
then it is further assigned to x.

But what seems to be going on here is
that 1 is first assigned to x, then
to x.thing (which causes an error).

Any reason why would Python deviate
from C in this regard?

Thanks!

Yingjie

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

the deceptive continuous assignments Yingjie Lan <lanyjie@yahoo.com> - 2011-12-06 03:06 -0800

csiph-web