gpt4 book ai didi

python - * : 'NoneType' and 'int' in Python 3 不支持的操作数类型

转载 作者:太空宇宙 更新时间:2023-11-04 02:42:16 24 4
gpt4 key购买 nike

我是 qt5 设计一个应用程序,这是我正在使用的功能序列。

self.u = 0
self.u = self.listWidget_3.itemClicked.connect(self.ClickRW1)

self.pushButton_2.clicked.connect(self.push4)

下面是ClickRW1函数

def ClickRW1(self, item):
self.y = item.text()
if self.y is "June":
return 0
elif self.y is "July":
return 1
elif self.y is "August":
return 2
else:
return 3

当 pushButton_2 被点击时,这个函数被调用

def push4(self):
plot_rain(self.z, self.u)

积雨函数-

def plot_rain(year, mont):
if year>2013:
year = year-1
n = year-2000
xc = np.zeros(4)
for i in range(0,4):
xc[i] = i
plt.plot(xc, predicted[((n*16)+(mont*4)):((n*16) + 4 + (mont*4))])
plt.show()

当我点击 pushButton_2 时。以下是错误-

plt.plot(xc, predicted[((n*16)+(mont*4)):((n*16) + 4 + (mont*4))])

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

最佳答案

self.uNone;您在此处将其设置为 None:

self.u = self.listWidget_3.itemClicked.connect(self.ClickRW1)

connect() 调用返回了None

然后将 self.u 传递给 plot_rain() :

def push4(self):
plot_rain(self.z, self.u)

它将该值用作 mont,因此 mont*4 失败。

解决方案是不要将 .connect() 结果赋值给任何东西,它不需要赋值:

self.u = 0
self.listWidget_3.itemClicked.connect(self.ClickRW1)

关于python - * : 'NoneType' and 'int' in Python 3 不支持的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46161859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com