[Chicago] Ode to <>

Ian Bicking ianb at colorstudy.com
Fri Sep 1 01:03:14 CEST 2006

Brian Ray wrote:
> On Aug 31, 2006, at 3:03 PM, Ian Bicking wrote:
>> Brian Ray wrote:
>>> Instead all together, it would be nice to be able to define our own
>>> operators from time to time.
>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
> Ok, this was not exactly what I was talking about. Interesting, none  
> the less.
> More, it may be handy to say:
> class ...
>    def operator !=(self, rhs):
>      if self.something != rhs.something:
>        return True
>      return False
> Or something along the lines of actually associating the operators  
> with classes.

Yes, "operator !=" is more clear than "__ne__", though I don't know how 
you'd spell "__ror__" or "__nonzero__", which are special methods that 
aren't associated with an operator (the first kind of is, but there's 
two methods associated -- __ror__ and __or__).

For anyone following along but unsure about these magic methods: 

If you really want a version of Python where you can *add* new 
operators, then you might want to look at Logix:


Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org

More information about the Chicago mailing list