Testing for Null?

Alex Bryan alexnbryan at gmail.com
Sat Jun 28 19:05:24 EDT 2008


I am having a problem with a list value that is empty. I have a list of
definitions called mainList. the 5th value in the list doesn't have anything
in it. In this case, the values are definitions; also, in this case just the
word cheese is defined. Here is my output to the console:


5.   a sprawling,weedy plant having small lavender or white flowers and
round, flat, segmented fruits thought to resemble little wheels of cheese.
6.
7.  an ingot or billet made into a convex, circular form by blows at the
ends.


I've made it so where the numbers, the period, and two spaces follow that,
then the definition. However, as you can see in 6, there is nothing. Here is
the code to print all this:

n=0

for x in mainList:
    if mainList[n] == "":
        print "Error on this definition"
    else:
        print str(n+1)+".  "+str(mainList[n])
    n=n+1

Now the two "" is where I need to figure out if it is empty. What is up
right now doesn't work; or at least doesn't give the desired result. So I
need to know how to write the if statement to make it work. This should be
simple, but I just don't know how to do it, never had this problem before.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080628/65f9f12b/attachment.html>


More information about the Python-list mailing list