[Python-ideas] getitem(obj, key, default) [was: Default return values to int and float]
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Oct 4 06:59:26 CEST 2011
Jan Kaliszewski wrote:
> Nick Coghlan dixit (2011-10-03, 13:03):
>
>>I'd sooner see a getitem/3 builtin
>>that could be used to ignore any LookupError the way dict.get/3 allows
>>KeyError to be ignored.
Well, maybe. Some useful properties of dict.get() are that
it avoids the overhead of catching an exception, and there
is no danger of catching something coming from somewhere
other than the indexing operation itself. You wouldn't get
those from a generic version.
--
Greg
More information about the Python-ideas
mailing list