【发布时间】:2012-02-28 23:39:07
【问题描述】:
所以我正在编写一个从配置文件中读取的脚本,并且我想完全按照此处概述的 configparser 的设计方式使用它:http://docs.python.org/release/3.2.1/library/configparser.html
我正在使用 Python 3.2.1。脚本完成后,将在 Windows 2008 R2 机器上运行,使用相同版本的 Python,或假设兼容,为当时的最新版本。
#!/user/bin/env python
import configparser
config = configparser.ConfigParser()
config.read('c:\exclude.ini')
config.sections()
读取 exclude.ini 文件效果很好 - 除非我有一个没有键的值。认为我可能做错了什么尝试解析此处列出的示例:http://docs.python.org/release/3.2.1/library/configparser.html#supported-ini-file-structure
它仍然每次都会抛出以下内容:
File "C:\Python32\lib\configparser.py", line 1081, in _read
raise e
configparser.ParsingError: Source contains parsing errors: c:\exclude.ini
[line 20]: 'key_without_value\n'
我不知所措...我实际上是从文档中复制/粘贴示例代码,以获取我正在使用的确切 python 版本,但它无法正常工作。我只能假设我错过了一些东西,因为我也找不到有类似问题的人。
【问题讨论】:
标签: python python-3.x configparser