如何解决错误“ NoneType”对象不可下标的问题?

时间:2018-07-24 17:35:25

标签: sql python-3.x

    conn = mysql.connector.connect(host="localhost",user="root",password="",db="mja_database")
    myCursor = conn.cursor()
    myCursor.execute("SELECT * FROM mja_attendance WHERE emp_num='%s'"%emp_numtb.get())
    res=myCursor.fetchone()
    if res[1] == None and res[3] == None:
        messagebox.showinfo("Notification", "No data in yet.")

错误是这个

  

“ NoneType”对象不可下标

2 个答案:

答案 0 :(得分:0)

如果我不得不猜测以挽救生命,那么当您通过以下方式进行检查时,我会认为res为“无”:

if res[1]...

也许放进去?

res=myCursor.fetchone()
if not res:
    messagebox.showinfo("Notification", "Res is None")
elif res[1] == None and res[3] == None:
    messagebox.showinfo("Notification", "No data in yet.")

如果您需要更多帮助,则应在问题中添加更多细节。

答案 1 :(得分:-2)

def resul(g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,g12,g13,g14):


    run=enter(g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,g12,g13,g14)
    d=run.Tmoy



    messagebox.showinfo(title="Resultat", message='NUT = {}\n E={} \nT1s ={} C°'.format( d[0], d[1], d[2]))





messagebox.showinfo(title="Resultat", message='NUT = {}\n E={} \nT1s ={} C°'.format( d[0], d[1], d[2]))
TypeError: 'method' object is not subscriptable