This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list bug
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: splyer, tim.peters
Priority: normal Keywords:

Created on 2006-06-15 17:03 by splyer, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg28804 - (view) Author: SPlyer (splyer) Date: 2006-06-15 17:03
When i define class with list member(in class body, not
in __init__ or other method) that list become common
for all instances of the class. So when i change list
member in one instance it also will changed in all the
other instances. OS - Windows XP(SP2)

[code]
class TestClass:
    t = []
    def __init__ (self):
        pass

a = TestClass()
b = TestClass()
a.t.append(123)
print b.t
[/code]
msg28805 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-06-15 17:14
Logged In: YES 
user_id=31435

Closing as Not-a-Bug.  That's exactly what should happen. 
If you want a different `t` per instance, use a different
`t` per instance instead of sharing a common `t` across all
instances  -- you simply got what you asked for here.  If
that's not what you want, then, e.g., put "self.t = []" in
your __init__ method.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43509
2006-06-15 17:03:18splyercreate