我正在尝试从Tkinter Gui将值插入sql数据库。但是我收到此错误ValueError:int(( 的文字无效,基数为 10:">这是代码:
con = cx_Oracle.connect("system/abc123")
print("connected")
cursor = con.cursor()
sql = "insert into student values('%d','%s','%d')"
rno = int(entRno.get())
name = entName.get()
marks = int(entMarks.get())
args = (rno,name,marks)
cursor.execute(sql % args)
con.commit()
msg = str(cursor.rowcount) + " records inserted"
messagebox.showinfo("Success",msg)
以下是回溯:
Traceback (most recent call last):
File "C:UsersAdminAppDataLocalProgramsPythonPython38libtkinter__init__.py", line 1883, in__call__
return self.func(*args)
File "C:UsersAdminDesktopTkinter Projectsam.py", line 108, in f5
rno = int(entRno.get())
ValueError: invalid literal for int() with base 10: ''
我应该怎么做才能解决这个问题?
我认为您可能想尝试在 try/except 块中传入 int 值。此链接看起来足智多谋: http://scipy-lectures.org/intro/language/exceptions.html 喜欢这个
try:
rno = int(rno)
break
except ValueError:
raise (ValueError, print(some debug message or warning issue)