我正在尝试使用python获取上周的日期。
如果日期为:2014年10月10日为
应该打印
10 OCT 2014, 09 OCT 2014, 08 OCT 2014, 07 OCT 2014, 06 OCT 2014, 05 OCT 2014, 04 OCT 2014
Run Code Online (Sandbox Code Playgroud)
我试过了:
today = (10 OCT 2014)
dates = [today + datetime.timedelta(days=i) for i in range(-4 - today.weekday(), 4 - today.weekday())]
print dates
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
exceptions.AttributeError: 'unicode' object has no attribute 'weekday'
Run Code Online (Sandbox Code Playgroud)