Empty list as default parameter
Alex Panayotopoulos
A.Panayotopoulos at sms.ed.ac.uk
Fri Nov 21 13:18:14 EST 2003
On Fri, 21 Nov 2003, anton muhin wrote:
> Alex Panayotopoulos wrote:
>
> > Was there any reason that this sort of behaviour was not implemented?
>
> It was discussed several times (search for it, if you're interested),
I have done so. It seems to be one of the most popular FAQs... 8^)
As I see it, this is not just a 'wart'; it's a major pitfall that seems
entirely out of place in python; everything up til now has made sense.[0]
The argument that this behaviour is useful for counters and such may have
been true in the past, but this was only ever a pseudo-generator hack. Now
we have real generators I don't see when you'd ever want to write
"foo(x=[])".
If it were up to me, I'd have def throw a warning wherever it sees a
square bracket, curly bracket or call to an __init__... But then I'm not a
python developer... 8^P 8^)
Okay, I've whinged enough, I think. No more posts from me on this subject.
8^)
> if you wish a one-linear, somehting like this might work:
> self.myList = myList or []
Thanks. That's sneaky without being confusing... I like.
--
<<<Alexspudros Potatopoulos>>>
Defender of Spudkind
[0] Though yes, I am happy that int division is to be changed.
More information about the Python-list
mailing list