The simplest way to read a file one line at a time is this:
for line in open('fileName'):
if 'str' in line:
break
No need for a with-statement or explicit close. Notice no variable 'f' that refers to the file. In this case python assigns the result of the open() to a hidden, temporary variable. When the for loop ends (no matter how -- end-of-file, break or exception), the temporary variable goes out of scope and is deleted; its destructor will then close the file.
This works as long as you don't need to explicitly access the file in the loop, i.e., no need for seek, flush, or similar. Should also note that this relies on python using a reference counting garbage collector, which deletes an object as soon as its reference count goes to zero.