Does everyone use #Python’s object()
for unique tokens? Like:
no_match = object()val = some_dict.get('key', no_match)if val is not no_match: do_something()
I don’t know what else object()
would be used for (and why they’d keep it).
@2ck
In Python, 'object' is the common base class of all classes.
Anyhow, I would use either:
if 'key' in some_dict: โฆ
if only existence is of interest
or
class no_match: pass
if value will be actually used (no need to instantiate an object) anyhow, rethinking: for the later, your way might be more efficient, I need to time it
@kirschwipfel i use the pattern in the OP for mappings where the cost of lookup is significant (e.g., ZODB BTree), and where the standard "not found" value of None is a legitimate value to store, and I need to know it was stored. it's come up in a couple situations
@kirschwipfel dope. thanks for letting me know ๐