Text files: iterating over the lines in the file : Text File Read « File « Python






Text files: iterating over the lines in the file



f = open("filename")
while 1:
    line = f.readline()
    if not line: break
    #process(line)

f.close()
           
       








Related examples in the same category

1.Demonstrates reading from a text file
2.Reading characters from the file.
3.Reading the entire file at once
4.Reading characters from a line.
5.Reading one line at a time.
6.Reading the entire file into a list.
7.Looping through the file, line by line.