I can't understand how works the code below:
class Host:
name = None
fileList = []
def __init__(self, hostName):
self.name = hostName
def AddInfo(self,file):
self.fileList.append(file)
def Cleanup(self):
self.fileList = []
I create 2 instances:
h1 = Host("hostName1")
h1.AddInfo("h1")
h1.Cleanup()
print h1.fileList, Host.fileList
h2 = Host("hostName2")
h2.AddInfo("h2")
print h2.fileList, Host.fileList
the result is:
h1.fileList = [], Host.fileList = ['h1']
h2.fileList = ['h1', 'h2'], Host.fileList = ['h1', 'h2']
why Host.fileList value is changed - I assigned new values to the instance only? why h2.fileList has such value - I was expecting ['h2'] here?