Message4469
| Author |
edloper |
| Recipients |
| Date |
2001年04月21日.23:25:51 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
My understanding of the augmented assignment
statements is that they should always assign to the
variable that they read from. However, consider the
following Python session:
>>> class A: x = 1
...
>>> a=A()
>>> a.x += 1
>>> a.x, A.x
(2, 1)
Here, the expression "a.x += 1" read from a class
variable, and wrote to an instance variable. A
similar effect can occur within a member function:
>>> class A:
... x = 1
... def f(s): s.x += 1
...
>>> a = A()
>>> a.f()
>>> a.x, A.x
(2, 1)
I have elicited this behavior in Python 2.0 and 2.1
under Linux (Redhat 6.0), and Python 2.0 on sunos5.
|
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 13:54:06 | admin | link | issue417930 messages |
| 2007年08月23日 13:54:06 | admin | create |
|