Spa*_*arc 16 python configparser python-3.x
所以我正在编写一个从配置文件中读取的脚本,我想准确地使用它如何设计如下所述:http://docs.python.org/release/3.2.1/library/ configparser.html
我使用的是Python 3.2.1.完成后,该脚本将在使用相同版本的Python的Windows 2008 R2计算机上运行,或者假定兼容性,即当时的最新版本.
#!/user/bin/env python
import configparser
config = configparser.ConfigParser()
config.read('c:\exclude.ini')
config.sections()
Run Code Online (Sandbox Code Playgroud)
这可以正常读取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'
Run Code Online (Sandbox Code Playgroud)
我很茫然...我真的从文档中复制/粘贴我正在使用的精确python版本的示例代码,但它不能正常工作.我只能假设我错过了一些东西,因为我也找不到任何有类似问题的人.
| 归档时间: |
|
| 查看次数: |
8575 次 |
| 最近记录: |