我正在尝试添加两个包含时间增量的计数器。添加计数器会引发以下问题:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 734, in __add__
if newcount > 0:
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
这引发了异常:
from collections import Counter
from datetime import timedelta
a = Counter(time=timedelta(microseconds=167242))
a + a
但是,这不会:
b = timedelta(microseconds=167242)
b + b