title: Iterating through a range of dates in Python
body: <p>I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list comprehension. </p>
  
  <pre class="lang-py prettyprint-override"><code>day_count = (end_date - start_date).days + 1
  for single_date in [d for d in (start_date + timedelta(n) for n in range(day_count)) if d &lt;= end_date]:
      print strftime("%Y-%m-%d", single_date.timetuple())
  </code></pre>
  
  <h2>Notes</h2>
  
  <ul>
  <li>I'm not actually using this to print. That's just for demo purposes. </li>
  <li>The <code>start_date</code> and <code>end_date</code> variables are <code>datetime.date</code> objects because I don't need the timestamps. (They're going to be used to generate a report).</li>
  </ul>
  
  <h2>Sample Output</h2>
  
  <p>For a start date of <code>2009-05-30</code> and an end date of <code>2009-06-09</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>2009-05-30
  2009-05-31
  2009-06-01
  2009-06-02
  2009-06-03
  2009-06-04
  2009-06-05
  2009-06-06
  2009-06-07
  2009-06-08
  2009-06-09
  </code></pre>