If you do it like this you are adding
Then you should use that attribute
new_var
as attribute to the dictionary.Then you should use that attribute
.
access,and not ['someting']
call.>>> config["Section"].new_var = "surname" >>> config['Section'].new_var 'surname' # Now dos this not work >>> config['Section']['new_var'] Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "C:\python37\lib\configparser.py", line 1251, in __getitem__ raise KeyError(key) KeyError: 'new_var'Can make both work but should
not
do this at all,just choice one method.>>> config['Section']['new_var'] = 'surename' # Now both work >>> config['Section'].new_var 'surname' >>> config['Section']['new_var'] 'surename'The problem now is that they are separate,changing one dos not affect the other.
>>> config['Section']['new_var'] = 'foo' >>> config['Section']['new_var'] 'foo' >>> config['Section'].new_var 'surname'