Python date range generator over business days

Viewed 18884

I'm trying to create a generator function to iterate over business days (weekdays), skipping weekends (and holidays would be nice too!). So far, I only have a function that simply iterates over days:

def daterange(startDate, endDate):
    for i in xrange(int((endDate - startDate).days)):
        yield startDate + timedelta(i)

I'm struggling to figure out a clean, efficient, and pythonic way to make the generator skip over weekends and holidays. Thanks in advance!

5 Answers
Related