I am trying to download a web page with python 2.7.13 and go line by line to analyze it. From memory and from searching around, I found that the following code snippet would be sufficient to go line by line:
with s as f:
for line in f:
print line
The variable s
is defined by a file.read() and the file is defined by urllib2 opening a specified url. Unfortunately, when I run the script, I get this syntax error:
Traceback (most recent call last):
File "a.py", line 12, in <module>
with s as f:
AttributeError: __exit__
I'm honestly dumbfounded of what I did wrong and it would be appreciated to gain insight about my mistake.