我正在尝试将一个timedelta
对象除以另一个来计算服务器的正常运行时间:
>>> import datetime
>>> installation_date=datetime.datetime(2010,8,01)
>>> down_time=datetime.timedelta(seconds=1400)
>>> server_life_period=datetime.datetime.now()-installation_date
>>> down_time_percentage=down_time/server_life_period
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'datetime.timedelta'
and 'datetime.timedelta'
我知道这个问题在Python 3.2中已经得到解决, 但在Python的早期版本中是否有处理它的便捷方式,除了计算微秒数、秒数和天数并进行除法之外?
谢谢,
Adam