Python Configobj-使用as\u bool读取值

Python Configobj-使用as\u bool读取值,python,boolean,configobj,Python,Boolean,Configobj,我有一个configobj文件,可以从中读取,但是我想使用as_bool方法从文件中读取一些值。目前我正在使用下面的代码,失败得很惨 configFile = 'config.conf' config = ConfigObj(configFile) del_files_bool = config.as_bool['Preferences']['delete_old_files'] 配置文件本身的结构如下 [Prefrences] delete_old_files = 1

我有一个configobj文件,可以从中读取,但是我想使用as_bool方法从文件中读取一些值。目前我正在使用下面的代码,失败得很惨

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

del_files_bool       = config.as_bool['Preferences']['delete_old_files']
配置文件本身的结构如下

[Prefrences]
delete_old_files = 1

我哪里做错了

尝试先提取节,如下所示:

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

根据他们的文档,阿斯布尔将key作为参数。 这应该起作用:

config['Preferences'].as\u bool('delete\u old\u files')

如果节中有子节,可以执行以下操作:


config['section']['sub-section']。作为_bool('key')

它在configobj版本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')
文件中提到了这些方法


希望有帮助

你怎么会失败?你会遇到什么错误?我从来没有使用过
ConfigObj
,但我猜你的意思是:配置['Preferences']['delete_old_files'].as_bool()?我会遇到以下错误。TypeError:“instancemethod”对象没有属性“getitem”