mutable default parameter problem [Prothon]

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Wed Jun 16 05:20:15 EDT 2004


On Tue, 15 Jun 2004 22:01:19 -0800, Troy Melhase wrote:

> $  find /usr/lib/python2.3/ -name "*.py" -exec grep "def.*=\[\]" {} \; | wc
> 
> And see 67 instances just in the standard library.

I don't know how you counted them:

[qrczak ~/src/python/Python-2.3.4]$ egrep 'def.*= ?\[\]' **/*.py | wc -l
45
[qrczak ~/src/python/Python-2.3.4]$ egrep 'def.*= ?None' **/*.py | wc -l
1420

Now consider that many of the Nones are a workaround for the current
Python behavior.

I agree that it's probably impractical to change Python rules because
some code relies on the current behavior. OTOH evaluating the default
argument each time when the function is applied is technically better.
This is one of warts which is hard to fix because of compatibility.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/




More information about the Python-list mailing list