List Behavior when inserting new items

André Malo auch-ich-m at
Tue Jan 30 07:36:51 CET 2007

* Paul McGuire wrote:

>> py>    def __init__(self, arg = []):
>> py>        self.__list = arg
> Please don't perpetuate this bad habit!!!  "arg=[]" is evaluated at
> compile time, not runtime, and will give all default-inited llists the
> same underlying list.

While this actually might be bad habit, the default arguments are *not*
eval'd at compile time. This seems to be a common mistake. They are
evaluated at runtime as everything else. The difference to other local
variables is, that the objects they're referring to are just initalized
once instead of each time they're taken into account.

die (eval q-qq[Just Another Perl Hacker
# André Malo, <> #

More information about the Python-list mailing list