擅长:python、mysql、java
<p>很简单,您从未将<code>diff</code>变量从三重值转换为<em>数值</em>小时数。相反,您将其格式化为可读字符串。将一个字符串乘以24得到24个副本,这些副本连接成一个字符串。。。在发布之前,您应该用一个简单的<code>print</code>语句验证一下。例如:</p>
<pre><code># "%d:%d:%d" % (diff.hours, diff.minutes, diff.seconds) = 04:26:03
totalTime = "%d:%d:%d" % (4, 26, 3)
totalProcessed = 73
denomCheck = totalTime*24
print "totalTime", totalTime
print "denomCheck", denomCheck
if denomCheck != 0:
unitsPerHour = totalProcessed/(totalTime*24)
</code></pre>
<p>输出:</p>
<pre><code>totalTime 4:26:3
denomCheck 4:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:34:26:3
Traceback (most recent call last):
File "so.py", line 8, in <module>
unitsPerHour = totalProcessed/(totalTime*24)
TypeError: unsupported operand type(s) for /: 'int' and 'str'
</code></pre>
<p>解决方案:</p>
<p>算算一下:</p>
<pre><code>total_time = diff.hours + diff.minutes/60.0 + diff.seconds/3600.0
</code></pre>
<p>如果您想学习如何操作一种使这些事情变得更简单的数据类型,请尝试Python的<code>datetime</code>包。你知道吗</p>