printing long string with a single write call
Question: I found a quite unexpected feature(or bug ?) when trying to write a long
string with a single `write` call using python (python 2.7.3-32 bit, windows
7).

Calling `print "a"*4000` prints on stdout a line that seems ok but calling
`print "a"*5000` just produces a line with 5000 white spaces instead of 'a'
character.

Would you have any idea of what is going wrong and how I can circumvent that
problem ?

Additional information:

using a newer version of python (2.7.5) still produces the same error. Here is
a snippet that produces the aformentionned problem.

    
    
    f = open("toto.dat","w",1000000)
    s = "a"*5000
    f.write(s)
    f.write("\n")
    f.close()
    

thanks a lot.

Eric


Answer: Maybe a problem of buffer ?

Try this please:

    
    
    from os import fsync
    
    fh = open("test.dat","w")
    s = "a"*5000
    fh.write(s)
    fh.write("\n")
    fh.flush()
    fsync(fh.fileno())
    fh.close()
    

There's no reason that closing the file-handler wouldn't empty the buffer and
write in the file, as far as I know, but who knows ?....

