Was: Is this an Bug in python 2.3?? Reflective relational operators

Dieter Maurer dieter at handshake.de
Wed Jun 16 14:48:50 EDT 2004


balaji at email.arizona.edu (Balaji) writes on 14 Jun 2004 11:37:42 -0700:
> ...
> In our application a expression 100>=x reads as 100 is an upper bound
> on x. Mathematically it is same as saying x<=100 which also bounds x
> by 100. But in modelling, the user wants to preserve the order in
> which he has written the expression.

Python's "rich comparison" methods have been defined for
comparisons and not for modelling. For any senseful definition
of ">=" and "<=", "x >= y" is equivalent to "y <= x".

As you seem to be interested in modeling and not in comparisons,
you must use your mapping of abstract syntax to objects
and can not use Python's default one.

The "ast" modul contains necessary prerequisites to implement
such a mapping. Recently, I found an example in Zope's
"RestrictedPython".


Dieter



More information about the Python-list mailing list