title: Most recent previous business day in Python
body: <p>I need to subtract <em>business days</em> from the current date. </p>
  
  <p>I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I currently have some pretty <strong>clunky</strong> code to do this:</p>
  
  <pre><code> lastBusDay = datetime.datetime.today()
   if datetime.date.weekday(lastBusDay) == 5:      #if it's Saturday
       lastBusDay = lastBusDay - datetime.timedelta(days = 1) #then make it Friday
   elif datetime.date.weekday(lastBusDay) == 6:      #if it's Sunday
       lastBusDay = lastBusDay - datetime.timedelta(days = 2); #then make it Friday
  </code></pre>
  
  <p>Is there a better way? </p>
  
  <p>Can I tell timedelta to work in weekdays rather than calendar days for example? </p>