Dear, I have a code to change dates of type string
in a text file to a list of dates of type datetime
:
import datetime as dt
import workdays
Holidays = open("C:\holidays.txt").readlines()
print (Holidays)
dates_list = [dt.datetime.strptime(date, '"%Y-%m-%d"').date() for date in
Holidays]
print(dates_list)
al leerlas con la funcion open("archivo.txt")
I have the following error: ValueError: time data '2017-09-18\n' does not match format '"%Y-%m-%d"'
. Apparently when reading the text a character \n
is generated at the end of the date and that's why I can not transform strings to date. The text file is UTF-8 without BOM.
greetings