Default attribute values pattern

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Jan 21 10:45:41 CET 2008


David Tweet a écrit :
(<ot>please, don't top-post</ot>)
> 
> def Grab(argdict, key, default):

cf pep08 for naming conventions...

>   """Like argdict.get(key, default), but also deletes key from argdict."""
>   if key in argdict:
>     retval = argdict["key"]
>     del(argdict[key])
>   else:
>     retval = default
>   return retval

def grab(kw, key, default=None):
   try:
     return kw.pop(key)
   except KeyError:
     return default

(snip)



More information about the Python-list mailing list