datetime.iterdate

Tim Peters tim.peters at gmail.com
Sun Jul 11 21:36:39 EDT 2004


[Robert Brewer]
> Anyone else tired of typing date-addition logic when iterating? It would
> be nice if the datetime package had something like:
> 
> def iterdates(first, last):
>    for day in range((last - first).days + 1):
>        yield first + datetime.timedelta(day)
> 
> ...notice the inclusive boundaries (i.e. last gets returned). This
> simple construct would make ugly date loops a lot cleaner:

I'm not a fan of building in every function that can (as you just
showed) be written easily in a couple lines of Python.  If something
like this ever is built in, it certainly won't be inclusive of the
endpoint -- that's too jarringly different from range().   And if
something like this ever is built in, it will also grow ugly variants
to increment by hours, minutes, months, years, weeks, quarter-hours,
...

I've noted before that I've not enountered another language community
so eager to bloat the language with things they can trivially do on
their own.  What's up with that?  I personally find Python functions
pretty easy to write -- even four-liners <wink>.



More information about the Python-list mailing list