By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

Re: Testing for Null?

P: n/a


Alex Bryan wrote:
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.
My guess is that your 'empty' value is something like ' ', which is not
equal to ''. Change str to repr and see better what item 6 is.

Jun 29 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.