MCPcopy Create free account
hub / github.com/ActiveState/code / get

Method get

recipes/Python/579113_defdict/recipe-579113.py:198–209  ·  view source on GitHub ↗

Behaves like standard dict.get, but uses value in _default attribute if no default parameter specified. >>> dd = DefDict({'a': 10}, 0) >>> dd.get('a'), dd.get('b'), dd.get('b', 11) (10, 0, 11) >>> print dd {'a': 10}

(self, key, *args)

Source from the content-addressed store, hash-verified

196 return dict.__getitem__(self, key) #may wish to allow dd[key] to insert key in dd with default value
197
198 def get(self, key, *args):
199 """Behaves like standard dict.get, but uses value in _default attribute
200 if no default parameter specified.
201
202 >>> dd = DefDict({'a': 10}, 0)
203 >>> dd.get('a'), dd.get('b'), dd.get('b', 11)
204 (10, 0, 11)
205 >>> print dd
206 {'a': 10}
207 """
208 if not args: args = (self._default,)
209 return dict.get(self, key, *args)
210
211 def copy(self):
212 """Return shallow copy of dictionary.

Callers 10

workerFunction · 0.45
GetTextMethod · 0.45
OnDoubleClickMethod · 0.45
mainFunction · 0.45
handlereturnFunction · 0.45
gethtmlFunction · 0.45
adjMethod · 0.45
flipOneEdgeMethod · 0.45
addPointMethod · 0.45
match_node_itemMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected