Bug in __init__?

Christian Heimes lists at cheimes.de
Fri Jan 18 12:20:28 EST 2008


Zbigniew Braniecki wrote:
> Any clue on what's going on here, and/if where I should report it?

Congratulations! You've stumbled over a well known gotcha. Most newbies
fall for the trap.

class A:
   def __init__ (self, val=[]):
     print val
     self.lst = val

val is created only *once* and shared across all instaces of A.

Christian




More information about the Python-list mailing list