« Controlling a powerUSB power strip from python on Mac OS X | Main | Demo of launching a traitsui GUI as a separate process and then communicating with it via STDIN/STDOUT »
Thursday
Oct022014

Head, meet wall - Do not use a mutable as a default parameter in python

Remember that default parameters in python are evaluated at the time of definition.

I knew this, I really did. Can it be Friday yet?

In the following for the BadIdea class a single list is created and every instance of BadIdea is referencing that same list. Far better to make the default None, test for that, and set to an empty list as necessary.