Comparison with False - something I don't understand

Harishankar v.harishankar at gmail.com
Thu Dec 2 02:28:30 EST 2010


When I run pychecker through my modules I get the message that 
comparisons with "False" is not necessary and that it might yield 
unexpected results.

Yet in some situations I need to specifically check whether False was 
returned or None was returned. Why is comparison with False so bad?

# example code which matches both False and None
if not var:
    # do something

# specifically check if False is returned 
# I don't want None
if var == False:
   # do something

So how do you get around this? My functions return False and None under 
different circumstances. Should I raise exceptions instead? I feel it's 
unnecessary clutter to use exceptions unless absolutely no other solution 
is available and yet I have doubts about the "False" value.

-- 
Harishankar (http://harishankar.org http://lawstudentscommunity.com)




More information about the Python-list mailing list