Since
Python 2.5, dict types provide a hook
__missing__ method, to be called when a key is not found. It can be used to implement some fancy dictionary types. However, sometimes it's error-prone that only
mydict[key] may trigger this method while
mydict.get(key) will NOT, which leads to inconsistent semantics.
No comments:
Post a Comment