Python date range generator over business days
python
Solution
I would strong recommend using the dateutil library for such tasks. A basic (not ignoring holidays) iterator over business days then simply is:
from dateutil.rrule import DAILY, rrule, MO, TU, WE, TH, FR
def daterange(start_date, end_date):
return rrule(DAILY, dtstart=start_date, until=end_date, byweekday=(MO,TU,WE,TH,FR))
Problem
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!