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}

def testfunc2(parm1,parm2=[]):
    print 'parm2',parm2
    parm2.append(5)

>>testfunc2('greg')
parm2 []
>>testfunc2('greg')
parm2 [5]

If it's not obvious what's wrong with this.  parm2 doesn't seem to be taking on its default value.  Maybe paramters aren't treated as local scope to the function
and it's taking some kind of global status?

And finally, how would I do what I'm trying to achieve?  ie If you don't specifiy parm2 it should be an empty dictionary.

Thanks,

--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to