我正在使用 configparser 来自动读取和修改名为“streamer.conf”的文件 conf。 我正在这样做:
import configparser
config = configparser.ConfigParser()
config.read('C:/Users/../Desktop/streamer.conf')
然后它分解并显示此错误消息:
MissingSectionHeaderError: File contains no section headers.
file: 'C:/Users/../Desktop/streamer.conf', line: 1
u'input{\n'
可能出了什么问题?任何帮助表示赞赏。
最佳答案
只需指定正确的编码
config.read(config_file_path, encoding='utf-8-sig')
- “utf-8-sig”表示带有 BOM 的 UTF-8
- “utf-8”表示没有 BOM 的 UTF-8
关于python - MissingSectionHeaderError : File contains no section headers. (configparser),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831956/