mutable default parameter problem [Prothon]

Mark Hahn mark at prothon.org
Wed Jun 16 15:40:10 EDT 2004


Andrea Griffini wrote:

> That's what I mean with "I'm new to python" :-)
>
>> def another( x ):
>>  y = getattr( another, 'static', 10 )
>>  another.static = x
>>  return y
>>
>> print another(1), another(2), another(4)
>
> I like more as an example:
>
>    >>> def foo(x):
>    ...   if not hasattr(foo,'list'):
>    ...     foo.list = []
>    ...   foo.list.append(x)
>    ...   print foo.list

In Prothon:

    def foo(x):
            print foo.list.append!(x)
    foo.list = []

(Sorry. I couldn't resist bragging.)





More information about the Python-list mailing list