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

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -