python - 属性错误 : 'datetime.date' object has no attribute 'date'

标签 python

我有一个这样的脚本:

import datetime

# variable cal_start_of_week_date has type <type 'datetime.date'>
# variable period has type <type 'datetime.timedelta'>

cal_prev_monday  = (cal_start_of_week_date - period).date()

执行上述语句时,出现错误:

AttributeError: 'datetime.date' 对象没有属性 'date'

如何解决这个问题?

最佳答案

停止尝试调用 date 对象的 date() 方法。它已经是一个日期

关于python - 属性错误 : 'datetime.date' object has no attribute 'date' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3195405/

相关文章:

python - 在Python中只打印整行的一部分

python - SQLAlchemy IntegrityError 违反约束名称

python - 类型错误 : must be real number, 不是 str

python - pandas 的两侧 t 检验

python - 如何删除列表中非空白元素之间的空白元素?

python - 正则表达式:搜索几个可能的组

javascript - 提取通过flask动态生成的checkbox的值

python - 控制 Matplotlib 图例框宽度以进行换行

python - 在 Pandas 中使用 .loc 将集合插入单元格时出现不一致的行为

python - 对段落/doc2vec 向量进行聚类时,合适的距离度量是多少?