I often see python code that accepts default arguments and has special behavior when not specified.
If, for example, I want this behavior:
def getwrap(dict, key, default = ??):
if ???: # default is specified
return dict.get(key, default)
else:
return dict[key]
If I rolled myself, I would get something like:
class Ham:
__secret = object()
def Cheese(self, key, default = __secret):
if default is self.__secret:
return self.dict.get(key, default)
else:
return self.dict[key]
But I do not want to come up with something stupid when there is a standard. What is the idiomatic way to do this in Python?
source
share