简体   繁体   English

如何使用基数 10 修复 int() 的无效文字:''?

[英]How to fix invalid literal for int() with base 10: ''?

Using python3.7 and tkinter to make a GUI, where I grab the input from 2 text boxes, and use a math formula then export it out.使用 python3.7 和 tkinter 制作一个 GUI,我从 2 个文本框中获取输入,然后使用数学公式将其导出。

I've looked through other forms and tried what they suggested and could not find how to fix it.我查看了其他表格并尝试了他们的建议,但找不到解决方法。 I've tried global inside and outside of the function, setting the variable before the function.我已经尝试在函数内部和外部使用 global,在函数之前设置变量。

def retrieve_input():
    global InputValue
    global InputValue2
    global Delay
    InputValue=tasks.get()
    InputValue2=proxies.get()
    print(InputValue)
    print(InputValue2)
    Delay=3500/int(InputValue)*int(InputValue2)
    print(Delay)
retrieve_input()
Label (window, width=12, text=Delay,bg="white",fg="Pink", font="none 22 bold") .grid(row=5, column=0,sticky=W)

Error:错误:

  File ", line 29, in retrieve_input
    Delay=3500/int(InputValue)*int(InputValue2)
ValueError: invalid literal for int() with base 10: ''

It means that you are passing in an empty string to the int class constructor.这意味着您将空字符串传递给 int 类构造函数。 You are effectively calling int('') .您正在有效地调用int('') It looks like either tasks.get() or proxies.get() are returning the empty string.看起来tasks.get()proxies.get()都返回空字符串。

In Short: Don't pass an empty string to int().简而言之:不要将空字符串传递给 int()。

As for the comment you left:至于你留下的评论:

try:
    Delay=3500/int(InputValue)*int(InputValue2)
except ValueError:
    pass
    #Handle a case in which the input is ''

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复&#39;ValueError:以10为基数的int()无效文字:&#39; - How to fix 'ValueError: invalid literal for int() with base 10:' 如何在我的代码中使用基数10修复“ValueError:int()的无效文字:&#39;&#39;” - How to fix the “ ValueError: invalid literal for int() with base 10: ' ' ” in my code 如何解决这个问题:ValueError:int() 的无效文字,基数为 10: - How to fix this: ValueError: invalid literal for int() with base 10: 如何修复 ValueError:int() 的无效文字,基数为 10:''? - How do i fix ValueError: invalid literal for int() with base 10: ''? 如何修复错误:int() 的文字无效,基数为 10:&#39;Luck&#39;? - How fix the error :invalid literal for int() with base 10: 'Luck'? 如何修复python脚本中的“int &lt;&gt;的无效文字,基数为10”错误 - How to Fix "invalid literal for int<> with base 10" error in python script 如何在Django中修复“基数为10的int()的无效文字” - How to fix “invalid literal for int() with base 10” in Django 如何修复值错误:int() 以 10 为底的无效文字 - How to fix value error : invalid literal for int() with base 10 如何在 python 中使用基数 2 修复 int() 的无效文字:''? - How to fix invalid literal for int() with base 2: ' ' in python? 如何使用基数 16 修复 int() 的无效文字:&#39;&#39;? - How to fix invalid literal for int() with base 16: ''?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM