-2

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

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Gotey
  • 449
  • 4
  • 15
  • 41
  • Please provide a [minimal example](http://stackoverflow.com/help/mcve) of code and input data that allows others to replicate the issue. It's hard to tell what you're doing, but you may want to try `'AA\n' in WORDLIST`. – jonrsharpe Aug 05 '14 at 13:35

1 Answers1

0

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.

Community
  • 1
  • 1
Mauro Baraldi
  • 6,346
  • 2
  • 32
  • 43