Python section key value ConfigParser

Using the ConfigParser has_section () method I can check if such a section exists in the file:

config.has_section(section_name) 

I wonder which team will check if the key exists . Thus, it would be possible to verify that both the section and the key exist before setting the value to the value using:

value = config.get(section, key)

Thanks in advance!

+4
source share
1 answer

In addition to has_sectionthere is also a method has_option:

config.has_option(section, option)

From the Python documentation :

has_option * (, ) *
, True; False. - None , DEFAULT.

+5

All Articles