Reading ascii files

By admin on 19 Feb | 0 comments

Today I was trying to write a scrit to read in an ascii file and out put the results to Excel. Still have to do the excel part but heres the readline in python

f = open('somefile.txt','r')
for line in f.readlines():
print line
f.close()
 
# ...and...
 
f = open('somefile.txt','r')
for line in f.read().split('\n'):
print line
f.close()
 
The xreadlines() function should be used for big files:
f = open('HUGE.log','r'):
for line in f.xreadlines():
print line
f.close()