Default attribute values pattern
davidtweet at gmail.com
Sun Jan 20 03:15:41 CET 2008
Ah! nice, thanks, knew I was probably missing something.
On Jan 19, 2008 5:01 PM, Arnaud Delobelle <arnodel at googlemail.com> wrote:
> On Jan 19, 11:02pm, "David Tweet" <davidtw... at gmail.com> wrote:
> > def Grab(argdict, key, default):
> > """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
> Dictionaries already have a method for this. It's called pop. It's a
> good idea to have a look at methods of builtin types before
> reimplementing the wheel!
> Grab(argdict, key, default) is argdict.pop(key, default)
More information about the Python-list