Overriding logical operators?
mwh at python.net
Mon Aug 23 16:56:44 CEST 2004
Andrew Durdin <adurdin at gmail.com> writes:
> In Python, you can override the behaviour of most operators for a
> class, by defining __add__, __gt__, and the other special object
> I noticed that, although there are special methods for most operators,
> they are conspicuously absent for the logical "or" and "and".
That's because they're not operators, they're flow control constructs.
Well, maybe that's not a helpful answer, but it's one you haven't had
> Would it be possible to allow overriding the logical operators, with
> the caveat that overriding it would prevent short-circuiting?
I think this would be a foul abomination. But maybe that's just me.
(I don't really approve of operator overloading either).
Ability to type on a computer terminal is no guarantee of sanity,
intelligence, or common sense.
-- Gene Spafford's Axiom #2 of Usenet
More information about the Python-list