Reading a file: readlines and xreadlines : File Readline « File « Python






Reading a file: readlines and xreadlines


file = open('test.txt', 'rb')
while 1:
    chunk = file.read(10)        # read byte chucks
    if not chunk: break
    print chunk,

for line in open('test.txt').readlines(): print line
for line in open('test.txt').xreadlines():print line
for line in open('test.txt'):             print line


           
       








Related examples in the same category

1.Read a file line by line
2.Reads a single line from the file