Strange results when comparing dates

Emile van Sebille emile at fenx.com
Wed Oct 31 06:40:43 EST 2001


"Grant Beasley" <gbeasley at tsa.ac.za> wrote in message
news:9roa85$5ll$1 at ctb-nnrp2.saix.net...
> Hi
>
> I'm using the cx_Oracle module to access an Oracle database, in doing so,
> I'm retrieving date time variables. According to the Python Database API,
I
> can use Timestamp to convert a time tuple (year, month, day, hour, minute,
> second) to a date time type variable as used by the cx_Oracle module. This
> works, and I can create these variables, but when comparing them I get
VERY
> strange results.
>


Consider:

>>> class Nothing: pass

>>> a = Nothing()
>>> b = Nothing()
>>> c = Nothing()
>>> c < b
0
>>> b < a
1

Why?  From Python22/Doc/ref/comparisons.html#l2h-288:

Most other types compare unequal unless they are the same object; the choice
whether one object is considered smaller or larger than another one is made
arbitrarily but consistently within one execution of a program.

My guess (I don't use cx_Oracle) is that cx_Oracle.Timestamp doesn't define
compare functions and that you'll need to roll your own.

<Insert JvR disclaimer here>

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list