Using default a empty dictionary as a default value

Diez B. Roggisch deetsNOSPAM at web.de
Tue Mar 22 11:41:31 CET 2005


C Gillespie wrote:

> Dear All,
> I ran my code through pylint to clean it up and one of the (many) errors
> it through up was
> Dangerous default value {} as argument
> Bascially, I have:
> 
> class NewClass:
>     def __init__(self,  myDict={}):
>         for key, value in myDict:
>             print key, value
> 
> Obviously, this is not the way it should be done. Should I have a default
> value of None for myDict and test for it? Or is there some other way?

Yes. That's the way to go.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list