我在使用python版本3.3.2時不斷收到這個錯誤,我沒有做任何事情,我正在看YouTube上的教程並嘗試過,但是他的版本使用2.7AttributeError:type object'challee'has no attribute'display'
>>> class challee:
def cname(self,name):
self.name = name
def display(self):
return self.name
def say(self):
print("help %s" % self.name)
>>> challee
<class '__main__.challee'>
>>> first = challee
>>> second = challee
>>> first.cname(first,"becky")
>>> second.cname(first,"tony")
>>> first.display()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
first.display()
AttributeError: type object 'challee' has no attribute 'display'
也許是縮進問題。你的兩個方法可能被當作方法'cname()'處理。 –
與縮進問題無關,您的代碼有另一個錯誤。你需要創建'challee'的實例,而不是使用類來完成所有的事情。 (Python 2.7會抓住這一點,但3.x行中的簡化刪除了該檢查。) – user2357112
您的權利它是縮進問題,我縮進了太多。 –