Why no data is displayed from file after writing in Python -


following code

#!/usr/bin/python sys import argv x, file_name = argv print "planning erase file %r. " , file_name tgt=open(file_name,'r+') print "deleting" tgt.truncate() print tgt.read() print " no lines " print "closed : ", tgt.closed print "mode : ", tgt.mode l1 = raw_input("line1 : ") l2 = raw_input("line2 : ") l3 = raw_input("line3 : ") tgt.write(l1) tgt.write('\n') tgt.write(l2) tgt.write('\n') tgt.write(l3) print "after writing" print tgt.read() print "going replace " tgt.close() 

last read statement not display data. file updated 3 lines entered. can help

you need read file once again moving cursor top

tgt.seek(0) print tgt.read() 

Comments