Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in configparser
#11
If you do it like this you are adding 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'
Reply


Messages In This Thread
Error in configparser - by fullstop - Dec-21-2019, 07:45 AM
RE: Error in configparser - by Larz60+ - Dec-21-2019, 08:15 AM
RE: Error in configparser - by fullstop - Dec-21-2019, 08:20 AM
RE: Error in configparser - by buran - Dec-21-2019, 08:26 AM
RE: Error in configparser - by fullstop - Dec-21-2019, 08:29 AM
RE: Error in configparser - by buran - Dec-21-2019, 08:56 AM
RE: Error in configparser - by fullstop - Dec-21-2019, 09:04 AM
RE: Error in configparser - by buran - Dec-21-2019, 09:14 AM
RE: Error in configparser - by snippsat - Dec-21-2019, 10:01 AM
RE: Error in configparser - by snippsat - Dec-22-2019, 06:44 PM
RE: Error in configparser - by fullstop - Dec-22-2019, 07:03 PM
RE: Error in configparser - by snippsat - Dec-22-2019, 07:36 PM
doubt in configparser - by fullstop - Dec-22-2019, 05:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ConfigParser(dict_type=) not behaving as expected malonn 5 3,365 Sep-08-2022, 08:42 AM
Last Post: malonn
  using alternate names in configparser Skaperen 6 2,896 Oct-01-2020, 08:27 PM
Last Post: Skaperen
Question configparser.NoSectionError (Python 3.7) alpho 2 5,872 Apr-08-2020, 10:26 PM
Last Post: micseydel
  Help with ConfigParser EricALionsFan 3 3,284 Jul-27-2018, 08:46 PM
Last Post: buran
  ConfigParser.NoSectionError: No section: 'Default' degenaro 1 14,516 Jun-08-2018, 08:33 PM
Last Post: ljmetzger
  No module named 'ConfigParser' Bani 13 56,522 May-22-2017, 08:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020