为什么我会收到无效文字错误?
我需要将 pyqt spinbox 中的两位数值分成两半以进行数学运算。为了做到这一点,我将值转换为字符串。这对于第一个数字效果很好,并且可以毫无问题地返回到整数。然而,第二个数字不会转换回来,并不断抛出以 10 为基数的无效文字错误。我做错了什么?我将小数位设置为 0,所以我不认为是这样。
w1 = self.doubleSpinBox_12.value()
w2 = self.doubleSpinBox_13.value()
w1a = str(w1)
w1b = w1a[:1]
w1c = int( w1b) * 12
w1b2 = w1a[1:]
w1b3 = int( w1b2)
w = w1c + w1b3
print w
I need to split a two digit value from a pyqt spinbox in half for math operations. In order to do this I'm converting the value to a string. This works fine for the first digit and it goes back to an integer without a problem. The second digit however won't convert back and keeps throwing a base 10 invalid literal error. What am I doing wrong? I have the decimal place set to 0 so I don't think it's that.
w1 = self.doubleSpinBox_12.value()
w2 = self.doubleSpinBox_13.value()
w1a = str(w1)
w1b = w1a[:1]
w1c = int( w1b) * 12
w1b2 = w1a[1:]
w1b3 = int( w1b2)
w = w1c + w1b3
print w
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要了解发生了什么,请在其中添加一些
print
:然后您就可以准确地看到其中的内容,包括任何不是基于 10 的有效文字的字符。
To find out what's going on throw some
print
s in there:then you can see exactly what's in there, including whatever characters are not base 10 valid literals.