Read a file line by line : File Readline « File « Python






Read a file line by line


file = open('test.txt')
while 1:
    line = file.readline()       # read line by line
    if not line: break
    print line,

file.close()
           
       








Related examples in the same category

1.Reading a file: readlines and xreadlines
2.Reads a single line from the file