1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/env python #coding:utf-8 import copy class B(object): b = 0 class A(object): b = 0 def __init__(self): self.a = B() a = A() b = a c = copy.copy(a) d = copy.deepcopy(a) a.a.b = 1 a.b = 1 print b.a.b, b.b print c.a.b, c.b print d.a.b, d.b