As far as I know, copy.deepcopy copies objects which contained in target object.
But my code doesn't work in this situation.
import copy
class MyClass(object):
list_value = [1, 2, 3, 4, 5]
def __init__(self, name):
self.name = name
a = MyClass('a')
b = copy.deepcopy(a)
a.list_value[0] = 10
print a.list_value
print b.list_value
The output was saying list_value
of b
instance is same with list_value
of a
.
[10, 2, 3, 4, 5]
[10, 2, 3, 4, 5]
What I expected was that list_value
of only a
changes.
Is there any thing I missed about deepcopy?