I am looking for a way to redirect output from Standard output to a file without a delay . Writing to a file seems ok using following code :
import time  
import sys,os
def test():
    j = 1
    while j < 10 :
        time.sleep(1)
        print("Python is good .Iteration ",j )
        j +=1
if __name__ == "__main__":
    myFile= open( "logFile.log", "w", 0 )
    sys.stdout= myFile
    test()
However , This only writes to the file on completion of the code i.e. after 9th iteration . I want to know if we can write data to file before completion of whole code and see the output in the file by maybe doing a tail -f logFile.log
Thanks in advance
 
     
     
     
    