The following code:
class House:
links = []
class Link:
pass
class Villa(House):
pass
if __name__ == '__main__':
house = House()
villa = Villa()
link = Link()
house.links.append(link)
print house.links
print villa.links
results in this output:
[<__main__.Link instance at 0xb65a4b0c>]
[<__main__.Link instance at 0xb65a4b0c>]
I find this very weird: Since it is another instance? - I would have expected that the output is - Since it is another instance?:
[<__main__.Link instance at 0xb65a4b0c>]
[]
When changing the line house.links.append(link)
to house.links = [link]
everything works as expected.
Can somebody explain this behavior?