TypeError:+ =不支持的操作数类型:“ datetime.timedelta”和“ NoneType”

马希
@property
def total_duration_of_videos(self):
    videos_qs = self.videos.all()
    total_duration = datetime.timedelta(0,0,0)
    for video in videos_qs:
        total_duration += video.total_time
    hours, remainder = divmod(total_duration.seconds, 3600)
    minutes, seconds = divmod(remainder, 60)
    return str(hours)+":"+str(minutes)+":"+str(seconds)

这就是我在这里写的内容,我并非无法找到解决方案。

博士 纳希杜尔·拉曼(Nahidur rahman)

对于某些video人来说videos_qsvideo.total_time正在回归None这就是为什么您得到错误。

要解决此错误改变total_duration += video.total_time线路total_duration += (video.total_time or datetime.timedelta(0,0,0))如下。

@property
def total_duration_of_videos(self):
    videos_qs = self.videos.all()
    total_duration = datetime.timedelta(0,0,0)
    for video in videos_qs:
        otal_duration += (video.total_time or datetime.timedelta(0,0,0))
    hours, remainder = divmod(total_duration.seconds, 3600)
    minutes, seconds = divmod(remainder, 60)
    return str(hours)+":"+str(minutes)+":"+str(seconds)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeError: 不支持的操作数类型 +: 'Timedelta' 和 'datetime.time - python

Python Pandas:TypeError:+不支持的操作数类型:“ datetime.time”和“ Timedelta”

Keras报告TypeError:+不支持的操作数类型:'NoneType'和'int'

TypeError:打印时%不支持的操作数类型:'NoneType'和'int'

TensorFlow 1.x:TypeError:/:不支持的操作数类型:'NoneType'和'int'

H2O异常TypeError:+不支持的操作数类型:'NoneType'和'unicode'

出现错误“TypeError:% 不支持的操作数类型:‘NoneType’和‘str’”

TypeError:+时不支持的操作数类型:求和列表时为“ int”和“ NoneType”

TypeError:%不支持的操作数类型:“ NoneType”和“ int”

TypeError:&:不支持的操作数类型:“ NoneType”和“ str”

Python:TypeError:+不支持的操作数类型:“ NoneType”和“ int”

TypeError:+不支持的操作数类型:“ NoneType”和“ list”

递归阶乘报告错误`TypeError:*不支持的操作数类型:'int'和'NoneType'`

TypeError:+不支持的操作数类型:“ NoneType”和“ int”

TypeError:+ =:Python 3中不支持的操作数类型为“ float”和“ NoneType”

TypeError: 不支持的操作数类型 +: 'NoneType' 和 'int' 在 while 循环中

如何修复,TypeError:% 不支持的操作数类型:'NoneType' 和 'int'

TypeError: 不支持的操作数类型 *: 'float' 和 'NoneType' 在构建 pyomo 模型时

TypeError: 不支持的操作数类型 +: 'NoneType' 和 'str'"?

试图解决“TypeError:+ 不支持的操作数类型:“NoneType”和“int”

蟒蛇 | TypeError: 不支持的操作数类型 /: 'NoneType' 和 'int' |使用变量来划分

* 不支持的操作数类型:“NoneType”和“NoneType”

python函数处理给出错误TypeError:不支持的操作数类型-:'NoneType'和'NoneType'

处理Bagging方法时,如何解决TypeError:+不支持的操作数类型:“ int”和“ NoneType”

训练GRU模型TypeError时出现此错误:*不支持的操作数类型:'int'和'NoneType'

TypeError:%的不支持的操作数类型:带有随机数生成器的'NoneType'和'tuple'?

TypeError:不支持的操作数类型 -:'datetime.time' 和 'datetime.time' 站点:stackoverflow.com

/不支持的操作数类型:'datetime.timedelta'和'datedelta'

% 不支持的操作数类型:“datetime.timedelta”和“int”