Feb-03-2022, 04:49 PM
I have the below code. I have one counter. if counter less than value set value It should write the value into excel.
in below code I could see counter printing 0 and hangs
The filed column should be written only once
I wanted to write into excel per 1S time sleep
Counter has to increment every time and save into SL no
I have used pyscripter 4
in below code I could see counter printing 0 and hangs
The filed column should be written only once
I wanted to write into excel per 1S time sleep
Counter has to increment every time and save into SL no
I have used pyscripter 4
import csv import datetime import time from datetime import datetime filename = "TestFormat.csv" fields = ['SLNo', 'Date','Time', 'RData', 'BData','GData','IRdata'] def main(): count=0 while(count<10): print("Counter:",count) now = datetime.now() Sln0=count date_Format=now.strftime('%Y/%m/%d ') current_time = now.strftime("%I:%M:%S") with open(filename, 'a+') as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(fields) csvwriter.writerow([Sln0,date_Format,current_time]) csvfile.close() count=count+1 if __name__ == '__main__': main() time.sleep(1)