Python 2.7.8 for line iteration error
Question: I want to iterate over all lines in a file with the following script

    
    
    import sys
    
    infile = open("test.txt")
    infile.read()
    
    for line in infile
        if line.find("This") != -1
            print line
    
    infile.close()
    

Unfortunately, I am getting this error message:

    
    
      File "getRes.py", line 6
        for line in infile
                         ^
    SyntaxError: invalid syntax
    

I've been trying for an hour to figure out what is the error and I am still
not able to find it. Can you tell me what is wrong and how to fix it?

PS: I am using Python 2.7.8, I would like to use this old version instead of a
more recent version.


Answer: You need a colon after any line that introduces a block in Python.

    
    
    for line in infile:
        if line.find("This") != -1:
    

