【问题标题】:TypeError: unsupported operand type(s) for /: 'float' and 'datetime.timedelta'TypeError:不支持的操作数类型/:'float'和'datetime.timedelta'
【发布时间】:2012-10-25 14:03:19
【问题描述】:

我有一个浮点值,我需要除以天数,计算如下:

import timedelta
import datetime
days_cur_cycle=abs(start_date.date()-today_date.date())
//start_date and today_date are datetime objects
x=3.09
y=x/days_cur_cycle`

这里出现以下错误

**TypeError: unsupported operand type(s) for /: 'float' and 'datetime.timedelta'**

请大家帮我计算一下

【问题讨论】:

    标签: python python-2.7


    【解决方案1】:

    我相信你会需要类似的东西: days_cur_cycle=abs((start_date.date()-today_date.date()).days)

    【讨论】:

      猜你喜欢
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2018-10-30
      • 2014-03-28
      • 2018-06-20
      • 2017-08-23
      • 1970-01-01
      相关资源
      最近更新 更多