Comparison with False - something I don't understand

Grant Edwards invalid at invalid.invalid
Thu Dec 2 10:31:47 EST 2010


On 2010-12-02, Steve Holden <steve at holdenweb.com> wrote:
> On 12/2/2010 9:13 AM, Harishankar wrote:
>> 
>> if not result:
>>     # error condition
>> 
>> Now above I first realized that the function can also return an empty 
>> list under some conditions and so changed it to
>> 
>> if result == False:
>>     # error condition
>> 
>> 
>> But now I realize that it's better to use "is"
>> 
>> if result is False:
>>     # error condition
>> 
>> That is how my problem arose.
>
> Did you think about using exceptions to handle exceptional conditions?
> If you are new to Python it may not be the obvious soltuion, but it can
> greatly simplify program logic.

If you're not used to using exceptions it may at first seem like they
take extra effort to use.  But usually, in the end, they end up being
less work (and more importantly easier to read and less bugs).

-- 
Grant Edwards               grant.b.edwards        Yow! He is the MELBA-BEING
                                  at               ... the ANGEL CAKE
                              gmail.com            ... XEROX him ... XEROX
                                                   him --



More information about the Python-list mailing list