Search code examples
pythonxlrd

Why aren't identical xlrd xldates the same?


In xlrd, why aren't identical-looking xldates considered the "same"

dates[0:10]
Out[92]: 
[xldate:41415.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0,
 xldate:41422.0]

cmp(dates[1],dates[2])
Out[95]: -1

I also tried using creating a list(set(list)) to single out the unique dates with no luck:

len(dates)
Out[96]: 1636

len(list(set(dates)))
Out[97]: 1636

Why aren't these the same?


Solution

  • Chances are, you are working with Cell objects. These objects are not comparable. You will want to compare the value that the cells are holding, not the cells themselves.

    # i.e., 
    cmp(dates[1].value, dates[2].value)