Last active
December 31, 2015 05:19
-
-
Save lwzm/7940253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dict(dict): | |
def __missing__(self, k): | |
return k | |
namespace = Dict() | |
eval("{a:1, b:c, 3:3, _:4}", None, namespace) | |
# T_T... I'm too late, see library/stdtypes.html#str.format_map | |
>>> class Default(dict): | |
... def __missing__(self, key): | |
... return key | |
... | |
>>> '{name} was born in {country}'.format_map(Default(name='Guido')) | |
'Guido was born in country' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment