bug or feature?

beza1e1 andreas.zwinkau at googlemail.com
Wed Oct 5 12:39:30 CEST 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()
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

More information about the Python-list mailing list