This will always print false. How can I check if the date is in the array and print the proper thing?
dates = [ "2012-09-03",
"2012-10-08",
"2012-10-09",
"2012-11-12",
# .. more values snipped for brevity
"2013-04-19",
"2013-05-27", ]
if date.today() in dates:
print "true"
elif date.today() not in dates:
print "false"
You are comparing strings with python
datetime.dateobjects; you need to convert the date object to a string for the comparison, using the.strftime()method:To illustrate this further:
Alternatively, you can use the
.isoformat()method, which uses the exact same output format: