How to search for a string in text files?

后端 未结 12 2421
死守一世寂寞
死守一世寂寞 2020-11-22 04:29

I want to check if a string is in a text file. If it is, do X. If it\'s not, do Y. However, this code always returns True for some reason. Can anyone see what i

12条回答
  •  时光取名叫无心
    2020-11-22 05:33

    if True:
        print "true"
    

    This always happens because True is always True.

    You want something like this:

    if check():
        print "true"
    else:
        print "false"
    

    Good luck!

提交回复
热议问题