method one:
Open = f ( " foo.txt " ) # returns a file object Line = f.readline () # readline call file () method the while Line: Print Line, # followed by ',' ignores newline # Print (Line , end = '') #. 3 used in the Python Line = f.readline () f.close()
Method Two:
for line in open("foo.txt"): print line,
Method three:
f = open("c:\\1.txt","r") Lines = f.readlines () # read the entire contents for Line in Lines Print Line