您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python-2.7 – 在Python 2.7中手动构建ConfigParser的深层副本

5b51 2022/1/14 8:22:37 python 字数 2117 阅读 550 来源 www.jb51.cc/python

刚开始我的 Python学习曲线,并将一些代码移植到Python 2.7.看起来在Python 2.7中,不再可能对ConfigParser的实例执行deepcopy().似乎Python团队对恢复这样的功能并不十分感兴趣: http://bugs.python.org/issue16058 有人可以提出一个优雅的解决方案来手动构建ConfigParser实例的深度复制/复制吗? 非常感谢,-Pe

概述

http://bugs.python.org/issue16058

有人可以提出一个优雅的解决方案来手动构建ConfigParser实例的深度复制/复制吗?

非常感谢,-Pete

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 – 在Python 2.7中手动构建ConfigParser的深层副本全部内容,希望文章能够帮你解决python-2.7 – 在Python 2.7中手动构建ConfigParser的深层副本所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶