Trying to parse csv dates (climate date) as datetime date objects but somehow "from datetime import date" gets forgotten. The error:
TypeError: 'str' object is not callable
is shown when calling date().
import csv
from datetime import date
file = 'nbcn-monthly_SMA_previous.csv'
with open(file, newline='') as csvfile:
readData = list(csv.DictReader(csvfile, delimiter=';', quotechar='|'))
meanTemp = {}
for i in readData:
date = i['date']
year = date[0:4]
month = date[4:6]
day = date[6:8]
from datetime import date # Without this it doesn't work
dateF = date(int(year), int(month), int(day))
mtemp = i['tre200m0']
meanTemp[date] = {'date':dateF, 'year':year, 'month':month, 'day':day, 'mmTemp':mtemp}
The code should work without the extra from datetime import date
but doesn't.
Sure, putting the extra import there works but this cannot be right.
The problem persists in the iPython shell. Run the script and the error is shown. Feed in date(1984,1,1) and the error is shown. Re-import date and everything is fine.
Anybody know what is wrong here?