Python File I/O issue: Bypassing For Loop?
<pre><code>def findWord(word):
    f = open("words.txt", "r")
    given_line = f.readlines()
    for line in f:
        if str(word) in line:
            part = line[0]
            ## print(line+"\n"+str(word)+" is a "+part)
            return True
        else:
            return False
    print("fail")
    f.close()

def partSpeech(inX):
    f = open("words.txt", "a")
    inX = inX.split()
    for i in inX:
        i = i.lower()
        if(findWord(i) == False):
            if "ify" in i[-3:] or "ate" in i[-3:] or "ize" in i[-3:] or "ing" in i[-3:] or "en" in i[-2:] or "ed" in i[-2:]:
                f.write("\nV"+i)
            elif "ment" in i[-4:] or "ion" in i[-3:] or "acy" in i[-3:] or "ism" in i[-3:] or "ist" in i[-3:] or "ness" in i[-3:] or "ity" in i[-3:] or "or" in i[-2:] or "y" in i[-1:]:
                f.write("\nN"+i)
            elif "ly" in i[-2:]:
                f.write("\nD"+i)
        else:
            print(i+" was already in the database.")
</code></pre>

<p>Essentially, my issue with the above happens at "for line in f:". The problem is that, after putting numerous markers (prints to determine where it's getting) throughout the code, the for loop isn't even ran! I don't understand, really, whether or not it's just that line or f aren't being counted or what, but.</p>

<p>The goal is to, in this snippet, take a bunch of words, loop them through a system that checks whether or not they're already in the given text file (the part I'm having issues with) and then, if they're not, append them with a part of speech tag.</p>

<p>EDIT: I'm not getting an error at all, it's just that it's not running the For Loop like it should. Every function is called at some point or another, partSpeech is called toward the end with a small list of words.</p>

<p>EDIT 2: PROGRESS! Sort of. The text file was empty, so it wasn't reading any line whatsoever. Now, however, it's not taking into account whether or not the words are already there. It just skips over them.</p>