PythonException:'类型错误:不支持的操作数类型(s)为divmod():'NoneType"和"int"

0

的问题

我有这个功能转换秒dd:hh:mm:ss(string)-但是,当存在空例从输入栏中,我收到了错误PythonException:'类型错误:不支持的操作数类型(s)为divmod():'NoneType"和"int".

有没有修复,可以把内部的功能,下面-

  def to_hms(s):
 m, s = divmod(s, 60)
 h, m = divmod(m, 60)
 d, h = divmod(h, 24)
 return '{}:{:0>2}:{:0>2}:{:0>2}'.format(d, h, m, s)
function pyspark python
2021-11-23 22:05:07
1

最好的答案

0

也许这可以帮助:

def to_hms(s):
    if s:
        m, s = divmod(s, 60)
        h, m = divmod(m, 60)
        d, h = divmod(h, 24)
        return '{}:{:0>2}:{:0>2}:{:0>2}'.format(d, h, m, s)
    return '0:00:00:00'

这个人会回来空的价值,如果它没有找到价值。

2021-11-23 22:22:43

伟大的工作究竟是如何必要的,谢谢!
JSingh1996

欢迎你们!
Sakshi Sharma

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................