Working on some code to decompose composite file names I was surprised to find that:
d = {}
d['file'] = d.get('file', {}).update({'two': 'file_two'})
print(d)
returns
{'file': None}
but I can get my desired result with
e = {}
temp = e.get('one', {})
temp.update({'two': 'file_two'})
e['file'] = temp
print(e)
which returns
{'file': {'two': 'file_two'}}
Please would someone explain why it's not possible to remove the use of the temporary variable. Thanks