[Python-ideas] fixing mutable default argument values

Jim Jewett jimjjewett at gmail.com
Thu May 3 00:00:10 CEST 2007


On 5/2/07, Joel Bender <jjb5 at cornell.edu> wrote:
>      @local(history = [])
>      def foo(x):
>          foo.history.append(x)

This assumes that the name "foo" won't be rebound underneath you.
That is usually, but not always, true.  __this_function__ from PEP
3130 would solve that gotcha.

> I like this because it keeps history out of the parameter list, and
> while it's not part of the local namespace, it's readily accessible.

Those are good things.

-jJ



More information about the Python-ideas mailing list