mutable default parameter problem [Prothon]

Peter Hansen peter at engcorp.com
Wed Jun 16 22:10:56 CEST 2004


Mark Hahn wrote:

> Andrea Griffini wrote:
>>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.)

About what?

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
 >>> def foo(x):
...   foo.list.append(x)
...   print foo.list
...
 >>> foo.list = []
 >>> foo('test')
['test']

(Oh, did you mean bragging about how a hard-to-see exclamation
mark causes append() to return the sequence?  I thought
maybe it was about the function attribute or something.)

-Peter



More information about the Python-list mailing list