Search code examples
pythonbooleanconfigobj

Configobj - reading a value using as_bool


I have a configobj file, which I am able to read from, however I'd like to read a few of the values from the file using the as_bool method. Currently I am using the following code and failing miserably!

configFile = 'config.conf'
config     = ConfigObj(configFile)

del_files_bool       = config.as_bool['Preferences']['delete_old_files']

The config file itself is stuctured like this

[Prefrences]
delete_old_files = 1

Where am I going wrong?


Solution

  • Try extracting the section first like this:

    config.get('Preferences').as_bool('delete_old_files')