Weird Python behaviour

Peter Otten __peter__ at web.de
Tue Aug 10 08:18:02 EDT 2010


Jonas Nilsson wrote:

> Lets say that I want to feed an optional list to class constructor:
> 
> class Family():
>     def __init__(self, fName, members = []):

> Why on earth is the output ['Bill', 'Joe']!? Is there a simple
> solution that separates f1 and f2 without forcing me to write code for
> the special case when you don't feed members to the __init__()-function?

Congrats; you just encountered a very popular new trap ;) The most recent 
explanation is only one day old:

http://mail.python.org/pipermail/python-list/2010-August/1252316.html

Peter



More information about the Python-list mailing list