Advertisement
rfmonk

copy_deep.py

Jan 15th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import copy
  5.  
  6.  
  7. class MyClass:
  8.     def __init__(self, name):
  9.         self.name = name
  10.  
  11.     def __cmp__(self, other):
  12.         return cmp(self.name, other.name)
  13.  
  14. a = MyClass('a')
  15. my_list = [a]
  16. dup = copy.deepcopy(my_list)
  17.  
  18. print '              my_list:', my_list
  19. print '                  dup:', dup
  20. print '       dup is my_list:', (dup is my_list)
  21. print '       dup == my_list:', (dup == my_list)
  22. print ' dup[0] is my_list[0]:', (dup[0] is my_list[0])
  23. print ' dup[0] == my_list[0]:', (dup[0] == my_list[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement