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).
@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 ๐
@2ck
I timed the code now: your approach "object()" is faster than mine "class xxx: pass". So I'm going to change my habits :-)
Thanks for sharing