Overloading and? was <RE: Should I prefer an external database>

Ian Bicking ianb at colorstudy.com
Tue Apr 22 13:07:21 EDT 2003


On Tue, 2003-04-22 at 09:52, Bjorn Pettersen wrote:
> > for paper in Paper.select(AND(Paper.q.title == 'foo',
> >                               Paper.q.author.startswith('Bob'))):
> 
> Does anyone know the reason for not allowing an overload of the and
> operator? (of course, the only use case I've seen is the one above
> [thrice, first time in 97] and alternate logical calculi [e.g. fuzzy
> logic] -- so not much different from some of the other operators? :-)

Certain operators (and, or, not, is) can't be overloaded.  (Actually, up
until 2.1, the kind of overloading I'm doing with the comparison
operators wasn't possible)

For and, or, and not you can overload (I believe the name is)
__nonzero__, and they use that to determine if the value should be
considered true or false.  But for an expression generator like this I
need to overload each operator so it returns a specific value, not just
True or False.  In this case a == b returns an object that evaluates to
"a = b" (for use in SQL).

  Ian







More information about the Python-list mailing list