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

查看:187
本文介绍了在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 =nofollow noreferrer>复制模块

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天全站免登陆