保持ConfigParser输出文件排序 [英] Keep ConfigParser output files sorted

查看:217
本文介绍了保持ConfigParser输出文件排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我的源代码控制,使用ConfigParser生成的输出文件的内容从不在同一个顺序。有时,部分将更改部分中的位置或选项,即使没有对值进行任何修改。

I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values.

有一种方法来保持在配置文件中排序,

Is there a way to keep things sorted in the configuration file so that I don't have to commit trivial changes every time I launch my application?

推荐答案

看起来这是修复在 Python 3.1 和2.7,并引入有序字典:

Looks like this was fixed in Python 3.1 and 2.7 with the introduction of ordered dictionaries:


标准库现在支持在多个
模块中使用
的有序字典。 configparser模块默认使用
。这让
配置文件被读取,修改,
,然后写回他们的
原始顺序。

The standard library now supports use of ordered dictionaries in several modules. The configparser module uses them by default. This lets configuration files be read, modified, and then written back in their original order.

这篇关于保持ConfigParser输出文件排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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