The minimal change is to use square brackets in your template, not the period:
# v Note >>> 'Hello {user[name]}'.format(**{'user': {'name': 'Markus'}}) 'Hello Markus'
Alternatively, put objects that actually have this attribute in the dictionary, for example. custom class or collections.namedtuple :
>>> class User(object): def __init__(self, name): self.name = name >>> 'Hello {user.name}'.format(**{'user': User('Markus')}) 'Hello Markus'
Note also that if you are writing a literal, you can simply use the keyword argument:
>>> 'Hello {user.name}'.format(user=User('Markus')) 'Hello Markus'
jonrsharpe
source share