Everything that I've read online says that the best way to open a file in python is:
with open('<filename>') as f:
for line in f.read().splitlines():
print line
That way you don't have to worry about forgetting to close the file. But I put this in an assignment in my python class and my professor marked points off saying that it was "VB style" (I have no idea what that means, Visual Basic style?) and that from now on I should open a file this way in python:
f=open('<filename>')
for line in f.read().splitlines():
print line
f.close()
That seems messy to me and like you would run the risk of forgetting to close one of your files, but then again I'm just a student. What's the best way to open a file in Python?