i have this problem;
i load in the IDLE a .txt with a bunch of different words, so in my code i want to assert that certain string included in the function i am defining is in this .txt file, but i keep getting AssertionError
for example, in my shell, for test if a word i know is in the file i put
--> 'AA' in WORDLIST
False
when the result i'm looking for it's 'True', because in the .txt i know there is an AA word writte it there thanks for help
I think I know what is causing your problem: a mistaken use of assert
.
Do not use assert
for comparisons. I'm guessing you're doing something like this:
assert 'word' in text_opened_file
The result of this is None
because assert
raises an exception if the condition is False
, but does not return True
if the condition is True
. Use if
and ==
to return True
or False
from your comparisons.
Here you can find a debate about effective use of assert
.