如何按时间划分Python

时间:2015-09-04 16:20:59

标签: python

我希望我的程序能够计算每分钟完成的工作量。

以下是该计划已经知道的内容:

ORIGINAL_NUM_OF_TOTAL_JOBS =这是告诉他们完成的工作数量 NUM_OF_TOTAL_JOBS_REMAINING =这是剩余的工作数

 print "\nTime Elapsed:" 
            TIME_ELAPSED = datetime.now() - STARTTIME
            print TIME_ELAPSED
            JOBS_PER_MINUTE = ORIGINAL_NUM_OF_TOTAL_JOBS - NUM_OF_TOTAL_JOB_REMAINING / TIME_ELAPSED
            print "\nAttempts/minute: "
            print JOBS_PER_MINUTE

我知道逻辑并不恰到好处,因为我将" time"时间不是必须=每分钟,但我卡住了。

来自python的输出/错误消息

Time Elapsed:
0:00:00.146000
Traceback (most recent call last):
  File "C:\Users\jlemming\Documents\NetBeansProjects\myscript.py\src\myscript.py", line 117, in <module>
    ATTEMPTS_PER_MINUTE = ORIGINAL_NUM_OF_TOTAL_ATTEMPTS - NUM_OF_TOTAL_ATTEMPTS / TIME_ELAPSED
TypeError: unsupported operand type(s) for /: 'int' and 'datetime.timedelta'

1 个答案:

答案 0 :(得分:1)

TIME_ELAPSEDdatetime.timedelta个对象(https://docs.python.org/2/library/datetime.html#datetime.timedelta)。它有方法total_seconds()。将其除以60以获得以分钟为单位的时间。

TIME_ELAPSED = datetime.now() - STARTTIME
minutes = TIME_ELAPSED.total_seconds() / 60.0
ATTEMPTS_PER_MINUTE = (ORIGINAL_NUM_OF_TOTAL_ATTEMPTS - NUM_OF_TOTAL_ATTEMPTS) / minutes