TA的每日心情 | 郁闷 2017-9-11 10:41 |
---|
签到天数: 16 天 连续签到: 1 天 [LV.4]测试营长
|
问题:为什么 get_info方法下 info['department'] =self.department.后没有联想出get_name()方法?手敲后运行也会报错提示没有get_name方法.哪儿错了?
代码:
#incoding:utf8
class Department:
def __init__(self,name):
self.name = name
def get_name(self):
return self.name
class Employee :
id = 0
def __init__(self,name,phone,salary,department):
Employee.id = Employee.id + 1
self.id = Employee.id
self.name = name
self.phone = phone
self.salary = salary
self.department = department
def get_salary(self):
return self.salary
def get_info(self):
info = {}
info['name']= self.name
info['phone'] = self.phone
info['salary'] = self.salary
info['department'] =self.department.get_name()
return info
hr = Department('hr')
zhangsan = Employee('zhangsan','1314444222','10000',hr)
print zhangsan.get_info()
|
|