import datetime
from dateutil.parser import parse
# Read in the list of holiday dates as a generator expression
with open('holiday.txt') as f:
holiday_dates = (parse(line.strip()) for line in f)
# Get the current date
today = datetime.datetime.now().date()
# Check if the current date is past the last holiday date
if today > max(holiday_dates).date():
# Send email to admin
print("Please update the holiday.txt file")
We use a generator expression to read in the holiday dates, which returns a generator object that yields the parsed dates one at a time. We then use the max() function to find and compare the latest holiday date with the current date. We also use the date() method to convert the datetime objects to date objects, which allows us to compare them directly with the today variable.
Note that the dateutil.parser.parse() method can handle a wider variety of date formats than datetime.datetime.strptime(), so you may not need to specify a format string for the dates in your file. However, if you know the exact format of the dates in your file, you can still use strptime() to parse them if you prefer.