(Python新手)继续收到“TypeError:'int'对象不可调用”

问题描述:

我对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() 
+1

什么是 “listMyData”? – michaelb 2014-10-01 01:51:29

+1

如果我们不知道任何方法和属性是做什么的,那么很难理解正在发生的事情。请将[MCVE](http://*.com/help/mcve)放在一起,以自包含的方式显示您的问题。 – MattDMo 2014-10-01 01:52:38

+0

对不起。 listMyData是一个与GUI中的文本框相对应的事件。我正在使用wxFormBuilder创建一个接口,将数字插入列表框中,然后单击两个按钮中的一个来查找最频繁的名称或最不频繁的名称。 – 2014-10-01 01:58:24

CountmyListData属性。你在它后面加上括号“()”,就好像它是一个函数,但它不是。这只是一个整数值。这将是这样做的:

y = 5 
x = y(word) 

这是没有意义的。我不确定你想要用wordmyListData.Count来做什么,但是也许你要找的是self.myListData[word].Count

As user3666197 mentioned,您还需要将float[...]更改为float(...)

omni has explained.Count属性问题。

您可能还需要行word_frequencies += float[ ...修订由于这样的:

>>> float[ 5 ] 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'type' object has no attribute '__getitem__' 
>>> float(5) 
5.0 
>>>