Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
你可以有一个常规的 Python 模块,比如 config.py,如下所示:
并像这样使用它:
You can have a regular Python module, say config.py, like this:
and use it like this:
您提供的示例配置实际上是有效的 YAML。事实上,YAML 可以满足您的所有需求,可以用多种语言实现,并且非常人性化。我强烈推荐你使用它。 PyYAML 项目 提供了一个很好的 python 模块,它实现了 YAML。
使用 yaml 模块非常简单:
The sample config you provided is actually valid YAML. In fact, YAML meets all of your demands, is implemented in a large number of languages, and is extremely human friendly. I would highly recommend you use it. The PyYAML project provides a nice python module, that implements YAML.
To use the yaml module is extremely simple:
我发现这是最有用且易于使用的
https://wiki.python.org/moin/ConfigParserExamples
您只需创建一个“myfile.ini” “像:
并检索数据,如:
I Found this the most useful and easy to use
https://wiki.python.org/moin/ConfigParserExamples
You just create a "myfile.ini" like:
And retrieve the data like:
Yaml 和 Json 是存储设置/配置的最简单且最常用的文件格式。 PyYaml 可用于解析 yaml。从 2.5 开始,Json 已经成为 python 的一部分。 Yaml 是 Json 的超集。 Json 将解决大多数用例,除了需要转义的多行字符串。 Yaml 也处理这些情况。
Yaml and Json are the simplest and most commonly used file formats to store settings/config. PyYaml can be used to parse yaml. Json is already part of python from 2.5. Yaml is a superset of Json. Json will solve most uses cases except multi line strings where escaping is required. Yaml takes care of these cases too.