python-2.7 – 在Python 2.7中手动构建ConfigParser的深层副本
发布时间:2021-01-17 04:37:40 所属栏目:Python 来源:互联网
导读:刚开始我的 Python学习曲线,并将一些代码移植到Python 2.7.看起来在Python 2.7中,不再可能对ConfigParser的实例执行deepcopy().似乎Python团队对恢复这样的功能并不十分感兴趣: http://bugs.python.org/issue16058 有人可以提出一个优雅的解决方案来手动构建
|
刚开始我的 Python学习曲线,并将一些代码移植到Python 2.7.看起来在Python 2.7中,不再可能对ConfigParser的实例执行deepcopy().似乎Python团队对恢复这样的功能并不十分感兴趣: http://bugs.python.org/issue16058 有人可以提出一个优雅的解决方案来手动构建ConfigParser实例的深度复制/复制吗? 非常感谢,-Pete 解决方法基于@Toenex答案,针对Python 2.7进行了修改:import StringIO import ConfigParser # Create a deep copy of the configuration object config_string = StringIO.StringIO() base_config.write(config_string) # We must reset the buffer to make it ready for reading. config_string.seek(0) new_config = ConfigParser.ConfigParser() new_config.readfp(config_string) (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Python 2.7.3中为numpy数组指定字段名称
- python – 改变seaborn heatmap颜色条上的刻度尺寸
- 是否有一种标准方法来声明不支持旧的python版本?
- `with canvas:`(Python`with something()as x:`)如何隐式
- python – pip install hyperopt和hyperas失败
- python – 让namedtuple接受kwargs
- 如何使用随机值验证单元测试
- django-rest-framework序列化器在多个视图中的不同字段
- python – Sublime Text 3 API:从文件获取所有文本
- python – 将日期列和时间列合并到datetime列
