python中的属性文件(类似于Java属性) [英] Properties file in python (similar to Java Properties)

查看:68
本文介绍了python中的属性文件(类似于Java属性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下格式(.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆