为什么在Python 3中有{Raw,Safe} ConfigParser? [英] Why is there {Raw,Safe}ConfigParser in Python 3?

查看:115
本文介绍了为什么在Python 3中有{Raw,Safe} ConfigParser?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令我惊讶的是,它有3种不同的形式:RawConfigParserSafeConfigParserConfigParser(文档).我读过这些差异,但是为什么每个人都不使用SafeConfigParser,因为它看起来安全吗?我可以理解,在Python 2的情况下,保留了另外两个是为了向后兼容.

Am surprised there's 3 different forms: RawConfigParser, SafeConfigParser and ConfigParser (docs). I read the differences but why isn't everyone using SafeConfigParser, since it seems, well, safe? I can understand that in the case for Python 2 that the other two were kept for backward compatibility.

更新:在Python 3.2中,SafeConfigParser已重命名为ConfigParser,并且旧的ConfigParser已删除(来源:

UPDATE: In Python 3.2, SafeConfigParser has been renamed to ConfigParser, and the old ConfigParser has been removed (source: NEWS for Python 3.2).

推荐答案

简而言之,请使用configparser.SafeConfigParser.

要引用文档,SafeConfigParser实现了更加理智的魔术插值功能的变体.此实现也更容易预测.如果新应用程序不需要与旧版本的Python兼容,则应首选此版本."

To quote the docs, SafeConfigParser "implements a more-sane variant of the magical interpolation feature. This implementation is more predictable as well. New applications should prefer this version if they don’t need to be compatible with older versions of Python."

为了向后兼容,似乎旧的ConfigParser仍存在于Python 3中:并非所有内容都向后不兼容!

It seems that the old ConfigParser still exists in Python 3 for backwards compatibility: not everything was made backward-incompatible!

这篇关于为什么在Python 3中有{Raw,Safe} ConfigParser?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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