jono jono - 1 year ago 60
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download