如何使用ConfigParser访问python文件中.properties文件中存储的属性

如何使用ConfigParser访问python文件中.properties文件中存储的属性,python,properties,config,configparser,Python,Properties,Config,Configparser,我有一个包含数据的.properties文件。我试图从python文件访问这些属性 我的属性文件如下所示: [section1] header = time, date, name, process_name, location [section2] content = timestamp, details 我在python中使用ConfigParser,我想访问如下属性: config.get("section1", header[0]) config.get("section2", co

我有一个包含数据的.properties文件。我试图从python文件访问这些属性

我的属性文件如下所示:

[section1]
header = time, date, name, process_name, location

[section2]
content = timestamp, details
我在python中使用ConfigParser,我想访问如下属性:

config.get("section1", header[0])
config.get("section2", content[2])
但现在,我得到了一个错误:“全局名称‘header’没有定义 "

如何解决此错误或如何使用位置号引用特定属性?

config.get('section1','header')
将返回
'time,date,name,process\u name,location'
。 然后使用
split
将其分解为
['time','date','name','process\u name','location']

print(config.get('section1', 'header').split(', ')[0])
# time

print(config.get('section2', 'content').split(', ')[1])
# details