2012-08-15 36 views
0

當運行下面的代碼時,我得到AttributeError: stat instance has no attribute 'printStats'。這裏有什麼問題?AttributeError:stat實例沒有屬性X?

class stat(): 
    def __init__(self, fname, blocks, backEdges): 
     self.fname = fname 
     self.blocks = blocks 
     self.backEdges = backEdges 

    def printStats(self): 
     print self.fname + str(self.blocks) + str(self.backEdges) 

element = stat("a", 1, 2) 
element.printStats() 

回答

5

您的縮進混亂,混合了製表符和空格。使用python -tt進行驗證。

+0

我正在使用選項卡,但python -tt告訴我,printStats不是選項卡。怎麼來的? – pythonic 2012-08-15 12:53:31

+0

...你問我爲什麼你的編輯器做了不同的事情嗎? – 2012-08-15 12:54:05

+0

好的,我現在已經排序了這個問題,謝謝。 – pythonic 2012-08-15 12:55:09

相關問題