Don't Understand This Error

Victor Subervi victorsubervi at gmail.com
Wed Dec 2 07:12:33 EST 2009


To those who caught the colon at the end of what I thought was going to be
def but turned out to be something else, thank.

On Wed, Dec 2, 2009 at 5:55 AM, Bruno Desthuilliers
<bruno.42.desthuilliers at websiteburo.invalid> wrote:

> On Wed, Dec 2, 2009 at 2:33 AM, Victor Subervi <victorsubervi at gmail.com>
>> wrote:
>>
>>>
>>> def colors(callingTable, which='', specificTables=[]):
>>>
>>
> Warning : default arguments are eval'd only once, at function creation
> time. This is a well known gotcha that can lead to unexpected behaviours
> like:
>
>
> def foo(x, bar=[])
>   bar.append("gotcha %s" % x)
>   print bar
>
> for i in range(5):
>   bar(i)
>

Thanks for this instructive example.
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091202/9ee4a318/attachment-0001.html>


More information about the Python-list mailing list