1

I was trying to read a boolean value using config parser, It finds the section fine but it fails finding the option for some reason.

configparser.NoOptionError: No option 'firsttime' in section: 'DEFAULT'

In the INI i have:

[DEFAULT]
"firsttime" = "true"

And in my main folder i have:

import configparser

config = configparser.ConfigParser()
print(config.getboolean('DEFAULT', 'firsttime'))

Lexi
  • 9
  • 4

1 Answers1

0

ConfigParser() constructs the configuration parsing object, but doesn't read in any configuration file. To do that you have to invoke its read method, e.g. config.read(<your_config_file>). So if your config file was named example.ini, your code would look like:

import configparser

config = configparser.ConfigParser()
config.read('example.ini')
print(config.getboolean('DEFAULT', 'firsttime'))

As a side note putting quotations in the init file will screw up the parsing of it. So you'll want your init file to look like:

[DEFAULT]
firsttime = true
Kirby
  • 15
  • 6