Today, I've been working on a small Python script involving keyword-arguments. Being a simple script, it has been quite easy to debug and overcome the problem.

However, if you make an error like this inside a larger application, well, you will have few chances of catching it without a good debugging tool.

Let's see the code:

>>> class MyClass(object):
...     def __init__(self, element, children=[]):
...             self._element = element
...             self._children = children
>>> c1 = MyClass(1)
>>> c1._children.append('foo')
>>> c2 = MyClass(2)
>>> c2._children

So, beware mutable keyword-arguments and remember that when you pass a list, you're not passing a copy, but an actual reference to it (ok, you cannot modify it, but you can change its state!).

EDIT: Thank you both semarj (and Daimon) for your answer on

EDIT2: Look at for more info.