我对python float比较逻辑感到疯狂,你们能让我知道我应该怎么做才能强制python做正确的比较:
(Pdb) type( nonOverlaps[-1].end )
<type 'float'>
(Pdb) type(interv.start)
<type 'float'>
(Pdb) p nonOverlaps[-1].end
381690.887195
(Pdb) p interv.start
381682.616861
#So, nonOverlaps[-1].end is LARGER than interv.start
(Pdb) p nonOverlaps[-1].end <= interv.end
True
(Pdb) p nonOverlaps[-1].end < interv.end
True
#OMG, this comparison return value should be False
答案 0 :(得分:2)
您的问题是代码中的拼写错误。您应该将nonOverlaps [-1] .end与interv.end进行比较,何时应该与interv.start进行比较。