This is my example script:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('conf.ini')
print bool(config.get('main', 'some_boolean'))
print bool(config.get('main', 'some_other_boolean'))
And this is conf.ini:
[main]
some_boolean: yes
some_other_boolean: no
When running the script, it prints True twice. Why? It should be False, as some_other_boolean is set to no.
Use
getboolean():From the Python manual:
Such as:
The
bool()constructor converts an empty string to False. Non-empty strings are True.bool()doesn’t do anything special for "false", "no", etc.