I have created a Python class like the following:
class Node(object):
"""docstring for Node"""
def __init__(self, node_id, lng, lat, gid, raw_data=[],quantized_data=[]):
super(Node, self).__init__()
self.node_id = node_id
self.lng = lng
self.lat = lat
self.gid = gid
self.raw_data = raw_data
self.quantized_data = quantized_data
Class Node has two attributes with default values, which are empty lists. Then I create two objects:
a = Node(1,1,1,1)
b = Node(2,2,2,2)
I find out that if I change raw_data
of one object, the other also changes.
For example:
a.raw_data.append('x')
Then b.raw_data also has x
:
>>> b.__dict__
{'node_id': 2, 'lng': 2, 'lat': 2, 'gid': 2, 'raw_data': ['x'], 'quantized_data': []}
I wonder why changing the attribute of one object affects the other. Obviously, they are two separate objects. What's wrong here or there's something I don't understand? Thanks