我創建了兩個類,我試圖測試它們,但我得到以下錯誤,並且我的生活中看不到錯誤。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