Reputation: 557
I'm extremely new to Python and I'm trying to write a program for a GUI to pull the most and least frequent name occurrences from a list for a class assignment. I keep getting a
TypeError: 'int' object is not callable
error on this code, and I know it has to do with the line:
word_frequencies += float[self.listMyData.Count(word)]/len[self.listMyData]
But I'm not sure exactly what the error is saying. I looked at similar questions on here but still wasn't sure exactly what I'm doing wrong. Any help would be greatly appreciated.
Here's the code in full:
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()
Upvotes: 0
Views: 1591
Reputation: 588
Count
is a property of myListData
. You put parentheses "()
" behind it, like if it were a function, but it isn't. It's just a set integer value. That would be like doing this:
y = 5
x = y(word)
Which doesn't make sense. I'm not sure what you're trying to do with word
and myListData.Count
, but maybe what you're looking for is self.myListData[word].Count
.
As user3666197 mentioned, you also want to change the float[...]
to float(...)
.
Upvotes: 5
Reputation: 1
omni has explained the .Count
property issue.
You also might want to revise the line word_frequencies += float[ ...
due to this:
>>> float[ 5 ]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object has no attribute '__getitem__'
>>> float( 5 )
5.0
>>>
Upvotes: 1