python读取文件报错_python ConfigParser读取配置文件,及解决报错ConfigParser.MissingSectionHeaderError: File contains no...

当使用Python的ConfigParser读取配置文件时,遇到ConfigParser.MissingSectionHeaderError错误,原因是文件可能存在BOM头。解决方法是通过正则表达式去除文件开头的BOM字节。本文提供了去除BOM的函数和读取配置文件的代码示例。
摘要由CSDN通过智能技术生成

先说一下在读取配置文件时报错的问题--ConfigParser.MissingSectionHeaderError: File contains no section headers

问题描述:

在练习ConfigParser读取配置文件时,cmd一直报一个错:ConfigParser.MissingSectionHeaderError: File contains no section headers.如图:

20180709140109423603.png

D:\test_python>python task_test.py

Traceback (most recent call last):

File "task_test.py", line 20, in

pp=ParsePageObjectRepositoryConfig()

File "task_test.py", line 9, in __init__

self.cf.read("D:\\test_python\\dataDriven\\conf\\PageObjectRepository.ini")

File "C:\Python27\lib\ConfigParser.py", line 305, in read

self._read(fp, filename)

File "C:\Python27\lib\ConfigParser.py", line 512, in _read

raise MissingSectionHeaderErr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值