【发布时间】:2023-03-14 09:45:01
【问题描述】:
我有 3.x 版本编写的 Python 脚本,由于环境限制,我需要在 2.7 中进行转换。
我设法重构了大部分语法差异和模块导入,但遇到了一行我不知道如何处理的问题:
def readConfigFile(self, file):
config = ConfigParser.ConfigParser(interpolation = ConfigParser.ExtendedInterpolation())
config.optionxform = str
config.read(file)
**config = ConfigParser.ConfigParser(interpolation = ConfigParser.ExtendedInterpolation())**
我在这里找到了一些参考( Python ConfigParser interpolation from foreign section) ,但我不知道如何替换(重构)。
配置解析器:
在 2.7 版本中:https://docs.python.org/2/library/configparser.html,但 ExtendedInterpolation() 不存在
在 3.x 版本中:https://docs.python.org/3.2/library/configparser.html,
所以我的问题是,有没有办法重构上面的代码以在 python 2.7 中工作并保留功能?
【问题讨论】:
标签: python python-2.7 refactoring interpolation