我创建了两个类,我试图测试它们,但我得到以下错误,并且我的生活中看不到错误。Python,类和继承测试
这个想法是使用这些类作为模块,然后从用户抓取输入来填充参数,但现在我只是测试类。
错误
File "./Employees.py", line 38, in <module>
emp1Atr.displayAttributes()
AttributeError: Attribute instance has no attribute 'displayAttributes'
代码如下
#!/usr/bin/python
class Employee:
'Practice class'
empCount = 0
def __init__(self, salary):
self.salary = salary
Employee.empCount += 1
def displayCount(self):
print "Total Employees %d" % Employee.empCount
def displayEmployee(self):
print "Salary: ", self.salary
class Attribute(Employee):
'Defines attributes for Employees'
def __init__(self, Age, Name, Sex):
def Age(self):
self.Age = Age
def Name(self):
self.Name = Name
def Sex(self):
self.Sex = Sex
def displayAttributes(self):
print "Name: ", self.Name + "\nAge: ", self.Age + "\nSex: ", self.Sex
emp1Sal = Employee(2000)
emp1Atr = Attribute(12, "John", "man")
emp1Sal.displayEmployee()
emp1Atr.displayAttributes()
我没有看到差异对不起 – k3eper
请看看。我已经更新了整个事情 –
感谢您的回应,请你解释你做了什么,我只是在学习几天,所以即时消息:( – k3eper