4 ms·
The comparison is being done between x_ts, which is a float, and x, which is a datetime object. Call be crazy but I think allowing this comparison to begin with
by nly 4y ago
The comparison is being done between x_ts, which is a float, and x, which is a datetime object. Call be crazy but I think allowing this comparison to begin with is the problem.
>>> from datetime import datetime
>>> ts = 1571595618.0
>>> x = datetime.utcfromtimestamp(ts)
>>> x_ts = x.timestamp()
>>> type(x_ts)
<class 'float'>
>>> type(x)
<class 'datetime.datetime'>
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- TotempaaltJ 4y agoThe code in the first example says `ts == x_ts`, not `ts == x`.
- nly 4y agoArgh.
- anttihaapala 4y agoThat's not the code from the article. The code in the article is comparing 2 floats. Though, equality operator would return `False` for comparison `x == x_ts` as well, instead of throwing an exception.