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

查看:90
本文介绍了在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.

推荐答案

我认为您想要< a href = http://docs.python.org/library/copy.html rel = noreferrer>复制模块

import copy

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

您可以通过与控制挑剔

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

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