Default attribute values pattern

cokofreedom at gmail.com cokofreedom at gmail.com
Mon Jan 21 11:09:09 CET 2008


> Grab(argdict, key, default) is argdict.pop(key, default)

"pop() raises a KeyError when no default value is given and the key is
not found."

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

So Bruno's technique seems to me to be the correct one as it catches
the KeyError.



More information about the Python-list mailing list