[python]為什麼父類的值沒有改變

大搜車-自娛發表於2012-06-07
在調式中已經發現第二次初始化worker的時候,worker的name已經為lisi了,為什麼列印結果仍然是111,新手望拍磚指導。

父類
class worker(object):
'''
classdocs
'''
name="111"
salary=""

def __init__(self,name,salary):
self.name=name
self.salary=salary
#print self.name,self.salary

def work(self):
print "I'm working"


子類
from worker import worker
class Tester(worker):
'''
classdocs
'''
name=""
salary=""
sex=""

def __init__(self,name,salary,sex):
worker(name,salary)
self.name=name
self.salary=salary
self.sex=sex

def boring(self):
worker.work(self)
print self.name,self.salary,self.sex



呼叫類:
from com.dianxinos.model.worker import worker
from com.dianxinos.model.Tester import Tester
class Hello:
def __init__(self):
#reload()
oneworker= worker("zhangsan","5000")
oneworker.work()
print oneworker.name,oneworker.salary
def test(self):
tester=Tester("lisi","10000","man")
tester.work()
#tester.boring()
print tester.name,tester.salary,tester.sex
print super(Tester, tester).name


if __name__ == "__main__" :
h=Hello()
h.test()


列印結果:
I'm working
zhangsan 5000
I'm working
lisi 10000 man
111
111

相關文章