python - Invalid output of file operation -


i not getting proper output good:

fo=open("test.txt","r+")  print "name of file:", fo.name  fo.write("life short..")  str=fo.read(3)  print "string in file :",str fo.close() 

when open file in python, maintains single pointer indicating place in file. pointer indicates next point read , next point written to. gets updated whenever read or write. when write "life short...", file pointer moved end of wrote. means when go read file, pointer past part wrote to. if want print out words wrote file, need move pointer beginning of file. can accomplished fo.seek(0).


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -