jono jono - 7 months ago 41
Python Question

Storing dates to skip in python config file

In my config I have

SKIP_DATES = ['2016-02-11', '2016-02-13']

Then in my script I have

if in config.SKIP_DATES:
print "Skipping date: {0}".format(

But this will not work because is a object and config.SKIP_DATES is a list of 'string dates'.

How can I easily get around this?

Can anyone suggest a better name for this post?


Your dates seem to be in the same format as date.isoformat():

Return a string representing the date in ISO 8601 format, ‘YYYY-MM-DD’. 
For example, date(2002, 12, 4).isoformat() == '2002-12-04'.

So you could do:

if in config.SKIP_DATES:
    print "Skipping date: {0}".format(

Note that the string representation of uses the same function:

For a date d, str(d) is equivalent to d.isoformat().

This is why print gives output like '2016-10-31'. Of course, you could then use a set instead of a list for storing your skip dates.