output truncated when writing to a file in python
<p>i have unusual problem, i'm using Anaconda and my python code runs really good the output on the screen is perfect, however, after each print i put file.write to write my result in my file as well but not all output is written there every time it truncates the output in different positions which doesn't make sense. the file was opened in 'w' mode. my code is really long like 400 line of code so its not possible to paste it here. 
i tried to close the console after each run and restart it but it doesn't always work i had a correct file output like just twice in 10 run tries. 
can any one tell me why is this happening ...your time is highly appreciated </p>

<pre><code>file.write("\n \n")
current=EventQueue.head
for i in range(0,EventQueue.size()):  
    print "*" *70
    file.write("\n In Time %s  " %str(current.index))
    file.write(str(current.data))
    print "In Time ",current.index , "  ",current.data
    current=current.next
    print "*" *70

file.close
</code></pre>

<p>when the size is equal to 25 there would be like only 16 or 19 output written in the file</p>

<p>i just added the parenthesses to the file.close it fixed the problem ... thanks and sorry for the </p>

python python-2.7