我對Python非常陌生,我正在嘗試編寫一個GUI程序來拉取最頻繁,最不頻繁的名稱事件從班級作業的列表中選擇。我一直對這個代碼獲得一個(Python新手)繼續收到「TypeError:'int'對象不可調用」
TypeError: 'int' object is not callable
錯誤,而且我知道它與線做:
word_frequencies += float[self.listMyData.Count(word)]/len[self.listMyData]
但我不知道到底是什麼錯誤說法。我在這裏看到類似的問題,但仍然不確定我做錯了什麼。任何幫助將不勝感激。
下面是完整的代碼:
import wx
import myLoopGUI
class MyLoopFrame(myLoopGUI.MyFrame1):
def __init__(self, parent):
myLoopGUI.MyFrame1.__init__(self, parent)
def clkAddData(self,parent):
if len(self.txtAddData.Value) != 0:
try:
myname = str(self.txtAddData.Value)
self.listMyData.Append(str(myname))
except:
wx.MessageBox("This has to be a name!")
else:
wx.MessageBox("This can't be empty")
def clkFindMost(self, parent):
unique_words = []
for word in range(self.listMyData.GetCount()):
if word not in unique_words:
unique_words += [word]
word_frequencies = []
for word in unique_words:
word_frequencies += float[self.listMyData.Count(word)]/len[self.listMyData]
max_index = 0
frequent_words =[]
for i in range(len(unique_words)):
if word_frequencies[i] >= word_frequencies[max_index]:
max_index = i
frequent_words += unique_words[max_index]
self.txtResults.Value = frequent_words
myApp = wx.App(False)
myFrame = MyLoopFrame(None)
myFrame.Show()
myApp.MainLoop()
什麼是 「listMyData」? – michaelb 2014-10-01 01:51:29
如果我們不知道任何方法和屬性是做什麼的,那麼很難理解正在發生的事情。請將[MCVE](http://stackoverflow.com/help/mcve)放在一起,以自包含的方式顯示您的問題。 – MattDMo 2014-10-01 01:52:38
對不起。 listMyData是一個與GUI中的文本框相對應的事件。我正在使用wxFormBuilder創建一個接口,將數字插入列表框中,然後單擊兩個按鈕中的一個來查找最頻繁的名稱或最不頻繁的名稱。 – 2014-10-01 01:58:24