f.write fails to recored inputs : Suppose such a text 

    In [134]: !cat test1.md                                                                                           
    The first test

I open it and write contents


    In [156]: f1 = open("test1.md", "r+")                                                                             
    
    In [157]: f1.write("The second test")                                                                             
    Out[157]: 15
    
    In [158]: !cat test1.md                                                                                           
    The first test
    test second method

It works correctly until now, if continue to input 

    
    In [159]: f1.write("The third test")                                                                              
    Out[159]: 14
    
    In [160]: !cat test1.md                                                                                           
    The first test
    test second method


    In [161]: f1.write("The fourth  test")                                                                            
    Out[161]: 16
    
    In [162]: !cat test1.md                                                                                           
    The first test
    test second method


What's the problem with `f.write`?
