Say I've got a dictionary with dots in the name of fields, like {'person.name': 'Joe'}
. If I wanted to use this in str.format
, is it possible?
My first instinct was
'Name: {person.name}'.format(**{'person.name': 'Joe'})
but this would only work if my dict were shaped like
{'person':{'name':Joe}}
The relevant manual docs section doesn't mention anyway of escaping the dot.
(Sidenote: I thought that generally
def func(**kw): print(kw)
func(**{'a.b': 'Joe'})
would cause an error, but the **
-expanded function call seems to work even if they're not valid identifiers! It does error out on non-strings though. o_O)