[Numpy-discussion] logical priority

Fernando Perez Fernando.Perez at colorado.edu
Mon Feb 7 21:26:10 CST 2005


Travis Oliphant wrote:

> Currently, I don't think Python allows "over-riding" the "and" 
> operation.  It only works on the truth or falseness of the objects.  
> Therefore, I don't think it is possible to make it work as you'd expect 
> unless Python is changed.

You are correct:

In [12]: dis.dis(compile('x and y','<console>','eval'))
   0           0 LOAD_NAME                0 (x)
               3 JUMP_IF_FALSE            4 (to 10)
               6 POP_TOP
               7 LOAD_NAME                1 (y)
         >>   10 RETURN_VALUE


There is no method you can hook in there.  Compare this to '&':

In [13]: dis.dis(compile('x & y','<console>','eval'))
   0           0 LOAD_NAME                0 (x)
               3 LOAD_NAME                1 (y)
               6 BINARY_AND
               7 RETURN_VALUE

Cheers,

f




More information about the Numpy-discussion mailing list