python中的复制构造函数? [英] Copy constructor in python?

查看:35
本文介绍了python中的复制构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python 中有复制构造函数吗?如果不是,我会怎么做才能实现类似的目标?

Is there a copy constructor in python ? If not what would I do to achieve something similar ?

情况是我正在使用一个库,并且我已经扩展了其中一个具有额外功能的类,并且我希望能够将从库中获取的对象转换为我自己的类的实例.

The situation is that I am using a library and I have extended one of the classes there with extra functionality and I want to be able to convert the objects I get from the library to instances of my own class.

推荐答案

我想你想要 复制模块

import copy

x = copy.copy(y)        # make a shallow copy of y
x = copy.deepcopy(y)    # make a deep copy of y

您可以像控制 pickle.

这篇关于python中的复制构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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