不,差不多就是这样。但是基于datetime.date.weekday()
结果的列表理解应该很容易:
today = datetime.date(2013, 06, 26)
dates = [today + datetime.timedelta(days=i) for i in range(-7 - today.weekday(), 14 - today.weekday())]
请记住,范围不必从0 开始。:-)
演示:
>>> import datetime
>>> from pprint import pprint
>>> today = datetime.date(2013, 07, 12)
>>> pprint([today + datetime.timedelta(days=i) for i in range(-7 - today.weekday(), 14 - today.weekday())])
[datetime.date(2013, 7, 1),
datetime.date(2013, 7, 2),
datetime.date(2013, 7, 3),
datetime.date(2013, 7, 4),
datetime.date(2013, 7, 5),
datetime.date(2013, 7, 6),
datetime.date(2013, 7, 7),
datetime.date(2013, 7, 8),
datetime.date(2013, 7, 9),
datetime.date(2013, 7, 10),
datetime.date(2013, 7, 11),
datetime.date(2013, 7, 12),
datetime.date(2013, 7, 13),
datetime.date(2013, 7, 14),
datetime.date(2013, 7, 15),
datetime.date(2013, 7, 16),
datetime.date(2013, 7, 17),
datetime.date(2013, 7, 18),
datetime.date(2013, 7, 19),
datetime.date(2013, 7, 20),
datetime.date(2013, 7, 21)]