我使用wxFormBuilder创建了一个GUI,允许用户在列表中输入"商家访问者"的名称,然后单击两个按钮之一,返回业务中最频繁和最不频繁的访问者.
我创建了一个早期版本,不幸的是,它给了我一系列访问者,而不是最常/最不常访问者的名字.我附上了我创建的GUI的屏幕截图,以帮助增加问题的清晰度(http://imgur.com/XJnvo0U).
一个新的代码版本采用了与早期版本不同的方法,我无法让它抛出任何东西.相反,我一直收到这个错误:
ValueError:max()arg是一个空序列
关于这一行:
self.txtResults.Value = k.index(max(v))
import wx
import myLoopGUI
import commands
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):
self.listMyData = []
unique_names = set(self.listMyData)
frequencies = {}
for name in unique_names:
if frequencies.get[name]:
frequencies[name] += 1
else:
frequencies[name] = 0
v = list(frequencies.values())
k = list(frequencies.keys())
self.txtResults.Value = k.index(max(v)) …Run Code Online (Sandbox Code Playgroud) 我对Python非常陌生,我正在尝试编写一个GUI程序,以便从列表中为类分配提取最频繁和最不频繁的名称.我一直在接受
TypeError:'int'对象不可调用
此代码出错,我知道它与该行有关:
word_frequencies += float[self.listMyData.Count(word)]/len[self.listMyData]
Run Code Online (Sandbox Code Playgroud)
但我不确定错误在说什么.我在这里看了类似的问题,但仍然不确定我做错了什么.任何帮助将不胜感激.
这是完整的代码:
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 …Run Code Online (Sandbox Code Playgroud)