Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : IndexError: tuple index out of range

In python i have this code

if record[0][1]:

the problem is.. when mysql does not return anything and thus..

record[0][1]

has no data..

this python code fails:

if record[0][1]:
IndexError: tuple index out of range

i simply want it to move on to the "else" statement or simply consider this if statement as .. invalid given that

record[0][1]

has no value. or data.. ( incoming stuff from mysql )

like image 807
user3880134 Avatar asked Aug 06 '14 20:08

user3880134


Video Answer


1 Answers

try:
    if record[0][1]:
        # Do stuff
except IndexError:
    pass
like image 90
celeritas Avatar answered Sep 30 '22 18:09

celeritas