pythonbooleanpychecker

What should replace comparisons with False in python?


I have a function that returns False if something isn't found, and returns a data structure with what I'm looking for otherwise. When I assign the value returned from this function to a variable my_var in a for loop, I do a if my_var == False: continue to carry on.

pychecker doesn't like this and reports Comparisons with False are not necessary and may not work as expected.

What's the python way for doing this?


Solution

  • As a return value indicating absence of a result, None is almost always better.

    To repeat myself: If at all possible, use None and test for my_var is None.