Handling the exception is the way to go:
try:
gotdata = dlist[1]
except IndexError:
gotdata="null"
Of course you could also check the len()
of dlist
; but handling the exception is more intuitive.
Handling the exception is the way to go:
try:
gotdata = dlist[1]
except IndexError:
gotdata="null"
Of course you could also check the len()
of dlist
; but handling the exception is more intuitive.