Function - Empty list as default parameter - not acting local?

Micah Elliott mde at micah.elliott.name
Tue Nov 15 23:35:38 EST 2005


On Nov 15, Gregory Piñero wrote:
>    Hey guys, could anyone explain this behavior to me.  It doesn't
>    seem right :-(
>    def testfunc(parm1,parm2={}):
>        print 'parm2',parm2
>        parm2['key1']=5
>    >>testfunc('greg')
>    parm2 {}
>    >>testfunc('greg')
>    parm2 {'key1': 5}

http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

-- 
_ _     ___
|V|icah |- lliott             <><             mde at micah.elliott.name
" "     """



More information about the Python-list mailing list