相关疑难解决方法(0)

使用Python获取上周日期?

我正在尝试使用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)

python datetime scrapy python-3.x python-datetime

5
推荐指数
1
解决办法
7115
查看次数

标签 统计

datetime ×1

python ×1

python-3.x ×1

python-datetime ×1

scrapy ×1