bug or feature?
beza1e1
andreas.zwinkau at googlemail.com
Wed Oct 5 06:39:30 EDT 2005
Coming back from a bug hunt, i am not sure what to think of this python
behaviour. Here is a demo program:
class A:
def __init__(self, lst=[]):
self.lst = lst
a = A()
b = A()
b.lst.append("hallo")
print a.lst # output: ["hallo"]
The point seems to be, that lst=[] creates a class attribute (correct
name?), which is shared by all instances of A. So a.lst ist the same
object as b.lst, despite the fact, that object a is different to object
b.
More information about the Python-list
mailing list