我创建了两个类,我正在尝试测试它们,但是我收到了以下错误,并且我一生都看不到有什么问题。
这个想法是将这些类用作一个模块,然后从用户那里获取输入以填充参数,但现在我只是在测试这些类。
错误
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()