print redirected to file SOMETIMES results in incomplete printout in python
Question: I want to save list to a file so I cycle through it and write it to file.
Everything's fine. But SOMETIMES(!?!?) the list is not written entirely, it
stops rendering in the middle of the item. No error is raised, it silently
continues executing rest of the code. I've tried several ways to write it out,
several versions of python (2.4, 2.5, 2.7) and it's all the same. It sometimes
work, sometimes not. When it's printed out to the terminal window, not to the
file, it's working properly without glitches. Am I missing something?

this is it

    
    
    ...    
    
    from bpnn import *
    
    ...
    
    # save input weights for later use:
    writewtsi = open("c:/files/wtsi.txt", "w")
    for i in range(net.ni):
        print>>writewtsi, net.wi[i]
    

bpnn is neural network module from here: <http://python.ca/nas/python/bpnn.py>


Answer: Close the file when done with all the writes to ensure any write-caching is
flushed to the drive with:

    
    
    writewtsi.close()
    

