我该如何解决-'文件包含无节头错误?

问题描述 投票:0回答:1

尝试使用此代码从.ini文件中获取一些数据,当我尝试打开.ini时,它给出我在做什么错?

config = configparser.ConfigParser()
config.sections()
config.read('FILE.ini') #throws file contains no section headers
print(config['DEFAULT']['toAddr'])
x = config.get('DEFAULT', 'to')

。ini文件

['DEFAULT']
to = "blah"

我在Win 10上使用Python 3.7 64

python ini
1个回答
1
投票

ini文件的标头中不应包含引号。

使用

[DEFAULT]
to = "blah"

代替

['DEFAULT']
to = "blah"
© www.soinside.com 2019 - 2024. All rights reserved.