因此,我正在编写一个从配置文件中读取的脚本,我想准确地使用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()
这很适合阅读排除.ini文件-除非我有一个没有键的值.考虑到我可能做错了什么,我try 解析下面列出的示例: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版本的示例代码,但它并没有正常工作.我只能假设我遗漏了什么,因为我也找不到有类似问题的人.