#coding=utf-8 f=open('text.txt','w') f.write('foo ') f.write('bar ') f.close() f=open('test.txt','r') for line in f: print line.rstrip()