[英]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. 我有一个configobj文件,可以读取,但是我想使用as_bool方法从文件中读取一些值。 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? 我要去哪里错了?
尝试像这样首先提取该部分:
config.get('Preferences').as_bool('delete_old_files')
According to their documentation , as_bool takes key as an argument. 根据他们的文档,as_bool将key作为参数。 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')
It works for me in configobj version 5.0.6: 它在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')
The documentation mention these methods here . 文档在这里提到了这些方法。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.