Comparison with False - something I don't understand
Martin v. Loewis
martin at v.loewis.de
Sun Dec 5 16:01:27 EST 2010
> result = myfunction (vars)
>
> 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 your function returns a list when successful, it should not return
False in the error case. Instead, it should return None (indicating that
there is no list).
Then the condition changes to
result = myfunction()
if result is None:
# error condition
Using None for "no result available" is very common in Python. Using
False for the same purpose (i.e. returning either a list or False)
is not. If you return False from a function, the only other possible
result should be True.
Regards,
Martin
More information about the Python-list
mailing list