0
while line_number < dictionary_elements_number and validation_bool == False:

getting this error when i run it throught pep8 E712 comparison to False should be 'if cond is False:' or 'if not cond:' isn't that a bit weird?

Clara
  • 33
  • 1
  • 2
  • 4
    Did you read the error message at all? – xander Jan 30 '18 at 12:49
  • 4
    "Isn't that a bit weird?" No. – internet_user Jan 30 '18 at 12:49
  • 3
    Either use: `while line_number < dictionary_elements_number and not validation_bool:` or `while line_number < dictionary_elements_number and validation_bool is False:` – James Jan 30 '18 at 12:49
  • i know how to fix it i just don't understand why i'm getting it. – Clara Jan 30 '18 at 12:51
  • 1
    It is considered poor programming practice in Python to use an equivalence comparison to `False` as a `True` value in a statement. It can be confusing to future people looking at your code. – James Jan 30 '18 at 12:53
  • 1
    @Clara Look at the answers here https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python – xander Jan 30 '18 at 12:54

2 Answers2

7

From PEP8 documentation:

Comparisons to singletons like None should always be done with is or is not, never the equality operators.

I guess False is also a singleton.

0

while line_number < dictionary_elements_number and validation_bool is False:

  • 3
    This seems to recommend the same solution as the existing accepted answer https://stackoverflow.com/a/48522050/7733418 , just less explained (i.e. not at all). Please [edit] to make the additional insight more obvious which you contribute. – Yunnosch Dec 22 '22 at 05:51