2

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?

jason
  • 35
  • 5

3 Answers3

3

Try extracting the section first like this:

config.get('Preferences').as_bool('delete_old_files')
Matt Sanders
  • 8,023
  • 3
  • 37
  • 49
Tom Ron
  • 5,906
  • 3
  • 22
  • 38
1

According to their documentation , as_bool takes key as an argument. This should work:

config['Preferences'].as_bool('delete_old_files')

If you have sub-sections inside sections, you could do this:

config['section']['sub-section'].as_bool('key')

nams
  • 141
  • 2
  • 3
0

It works for me in configobj version 5.0.6:

config['section1'].as_bool('key1')

config['section1'].as_int('key2')

config['section1']['sub-section'].as_float('key3')

config['section1']['sub-section'].as_list('key4')

The documentation mention these methods here.

Hope it helps!

Nick Martin
  • 731
  • 3
  • 17