Python checking for None/Null values

Fuzzydave Fuzzygoth at gmail.com
Fri Aug 11 06:13:24 EDT 2006


Okay, I have been handed a python project and working through it I have

had to add a report. I am returning 10 variables the results of an SQL
Query
and as usual the number of results vary from 1 result to 10 results so
I
implemented a check to see if the array item was empty or not. The code

is below based upon the code already in the python project i was
handed.

history8=historyRep[8]
    if history8!=None:
        history8=cmi.format_history(historyRep[8])
    else:
        history8=''

and

if historyRep[8]!=None:
    history8=cmi.format_history(historyRep[8])
else:
    history8=''

but regardless i am getting the error below and i can't seen to resolve
this, what am i
doing wrong?

Traceback (most recent call last): File
"/home/phillipsd/work/medusa-new/htdocs/pricingrep.cgi", line 326, in ?
if historyRep[8]==None: IndexError: list index out of range


David P




More information about the Python-list mailing list