I used following code for writing the datetime to a csv file.
csvdata=[datetime.datetime.now()]
csvFile=open("Datetime.csv","w")
Fileout=csv.writer(csvFile, delimiter=',',quoting=csv.QUOTE_ALL)
Fileout.writerow(csvdata)
Eventhough the file is creating it have no data in it.What should i do in extra for getting the data in csv.
The problem is that the writing of the file is buffered, and does not happen immediately. You should close your file descriptor to flushes any unwritten data:
csvFile.close()
Or just use with statement (recommended):
csvdata = [datetime.datetime.now()]
with open("Datetime.csv","w") as csvFile:
Fileout = csv.writer(csvFile, delimiter=',', quoting=csv.QUOTE_ALL)
Fileout.writerow(csvdata)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With