lwzm
12/13/2013 - 5:45 AM

eval_improved.py

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'