View Full Version : [Python] EOF()

May 12th, 2011, 09:33 PM
I need to read a file line by line into a dictionary with a while loop.

fob = open("file.txt", "r")
dict = {}
while not EOF(fob):
a = fob.readline()
b = fob.readline()
dict[a] = b

This is basically what I want to do, but I can't find an EOF command online for python.

May 12th, 2011, 09:47 PM
You don't need it. You can read a file as follows:

for line in fob:
# do something

which will walk over all lines in the file.