Default list parameter issue
Olivier Boudeville
olivier.boudevilleNOSPAM at online.fr
Fri Aug 6 13:21:17 EDT 2004
Oh, thanks a lot Peter, I did not know about it and was totally stuck.
IMHO, this 'feature' is counter-intuitive. Maybe it allows to write in
some cases simplier or more efficient functions, but there are enough
traps not to add more of them, with this kind of side-effects.
I believed, with filter, list comprehension and so on, that python was
making some steps towards 'functional programming' and declarative
languages (sorry if the translations are not accurate). It would have
led to more robust code. It is certainly not that way that recursive
functions will be easy to write and understand (but it is just my
opinion) !
I do not find/wish this behaviour is 'pythonic', but of course it is a
matter of taste.
Thanks again nevertheless, it helped me a lot !
Olivier.
Peter Otten wrote:
> Olivier Boudeville wrote:
>
>
>>I do not understand why using an empty list as default parameter results
>> in such a different behaviour.
>
>
> You are not alone.
>
> http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects
>
> Peter
More information about the Python-list
mailing list