variable & scoping question.

Diez B. Roggisch deets at nospam.web.de
Mon Aug 10 17:12:29 CEST 2009


Cornelius Keller wrote:

> Hi,
> 
> I'm a quite fresh python programmer, (6 Month python experience).
> Today I found something I absolotly don'nt understand:
> 
> given the following function:
> 
> def test_effect(class_id=None,class_ids=[]):
>     if class_id is not None:
>         if class_id not in class_ids:
>             class_ids.append(int(class_id))
> 
>     print class_ids
> 
> I observe that the class_ids array is growing when it is called with
> different class id's.
> 
> I expected class_ids to be [] if the keyword argument is not set, but
> it seems to beahve like a static variable if not set.

http://effbot.org/zone/default-values.htm

Diez



More information about the Python-list mailing list