python中的属性文件(类似于Java属性) [英] Properties file in python (similar to Java Properties)
问题描述
给定以下格式(.properties 或 .ini):
Given the following format (.properties or .ini):
propertyName1=propertyValue1
propertyName2=propertyValue2
...
propertyNameN=propertyValueN
对于 Java,有 Properties 类,提供解析/与上述格式交互的功能.
For Java there is the Properties class that offers functionality to parse / interact with the above format.
python 的标准 库 (2.x) 中是否有类似的东西?
Is there something similar in python's standard library (2.x) ?
如果没有,我还有什么其他选择?
If not, what other alternatives do I have ?
推荐答案
对于 .ini 文件,有 ConfigParser 模块,提供与 .ini 文件兼容的格式.
For .ini files there is the ConfigParser module that provides a format compatible with .ini files.
无论如何,没有什么可用于解析完整的 .properties 文件,当我必须这样做时,我只是使用 jython(我说的是脚本).
Anyway there's nothing available for parsing complete .properties files, when I have to do that I simply use jython (I'm talking about scripting).
这篇关于python中的属性文件(类似于Java属性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!