I have a text file with rows like this..
(datetime.datetime(2017, 1, 1, 4, 16), 0.17799999999999999)
(datetime.datetime(2017, 1, 1, 4, 26), 0.20000000000000001)
(datetime.datetime(2017, 1, 1, 4, 36), 0.17699999999999999)
Ultimately I want to read in the data and plot the date against the value, but I'm currently stuck on just getting the data read.
So far I have
f=open('data.txt', 'r')
for line in f:
line = line.strip()
columns = line.rsplit(',',1)
date=columns[0][1:]
print(date)
Sample output:
datetime.datetime(2017, 1, 1, 4, 36)
But I would like it to print as a date e.g. 20170101 04:36:00 (or similar)
I don't know how to get the datetime object to to get recognized as such, and display as a real date string. If I google it I see loads of info on turning a string to a datetime object but nothing for the other way round.
Many thanks in advance.