So this has been answered here: making output of datefinder into list Unfortunately my rep is too low so I can't comment to get clarity on why it's not functioning as expected. I want to take filename strings and turn them into a list of dates so that I can then use them as a fill for the date column. All of the filenames include event dates, but they are not on the sheets themselves. The format is: CompanyNameEventLocationDDMMYYYY.xlsx
import glob
import datefinder
#get all Excel files within folder
path = r"C:\Users\me\Documents\Events\Spreadsheets\Consolidated\*.xlsx"
filename = glob.glob(path)
#get dates from filenames
event_dates = (datefinder.find_dates(f) for f in filename)
#check output
for days in event_dates:
print(days.strftime("%Y-%m-%d %H:%M:%S"))
Instead of getting converted objects I get the following error: AttributeError:
'generator' object has no attribute 'strftime'
When I try converting it directly to a list with
date_list = list(event_dates)
print(event_dates)
I still get output saying that it's still a generator object:
<generator object <genexpr> at 0x00000230571AE660>
What do I need to change so that it actually becomes a list of datetimes that I can use to populate an appended 'Date' column by forward filling?