Python 3.4 Issue with writing to a file with time.sleep()
Question: I am using Python 3.4. I'm trying to figure out why the writerow() is not
working if I put a sleep timer at the end it does not write the data to the
Test.dat file. The code looks like this

    
    
    import csv, time
    
    fileName = "Test.dat"
    freq = 5; 
    
    with open(fileName, 'a') as fp:
        a = csv.writer(fp, delimiter=',')
        for i in range(1, 10):
            data = [2014, 5, 3, 5, 26, 53, 'Price', '100.00']
            a.writerow(data)
            time.sleep(freq)
    

But then if I remove the timer it writes the data in the Test.dat file

    
    
    import csv, time
    
    fileName = "Test.dat"
    freq = 5; 
    
    with open(fileName, 'a') as fp:
        a = csv.writer(fp, delimiter=',')
        for i in range(1, 10):
            data = [2014, 5, 3, 5, 26, 53, 'Price', '100.00']
            a.writerow(data)
    

Ans:

    
    
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    2014,5,3,5,26,53,Price,100.00
    


Answer: you are waiting 5 sec and the program take a along time to end write the file
:

wait one second ::

    
    
    freq = 1;
    

