[Python]Shallow and Deep copy operation

时间:2014-03-02 09:09:59   收藏:0   阅读:668

The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances).

import copy

class MyKlass(object):
    def __init__(self,name):
        self.name = name
    def test(self):
        print "this is " + self.name

class MyDict(dict):
    pass

def myFunction():
    print "this is function"


if __name__ == ‘__main__‘:
    k = type(MyKlass)
    print k    
    NewClass = copy.copy(MyKlass)
    NewClass("Python").test()
    d = type(MyDict)
    print d.__base__
    f = type(myFunction)
    print f.__name__


[Python]Shallow and Deep copy operation,布布扣,bubuko.com

原文:http://blog.csdn.net/wonderfan/article/details/20206879

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!