Skip to content

Instantly share code, notes, and snippets.

@lwzm
Last active December 31, 2015 05:19
Show Gist options
  • Save lwzm/7940253 to your computer and use it in GitHub Desktop.
Save lwzm/7940253 to your computer and use it in GitHub Desktop.
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