Operator Overloading

Peter Maas peter at somewhere.com
Thu Nov 25 10:25:39 CET 2004


Sebastien Boisgerault schrieb:
> I wonder if the following quotation from the Python Reference Manual 
> (release 2.3.3) about operator overloading is true :
> 
> "For example, if a class defines a method named __getitem__(), and x
> is
> an instance of this class, then x[i] is equivalent to
> x.__getitem__(i)"
[...]
>>>>from Numeric import *
>>>>a = array([0.5])
>>>>a[0]
> 
> 0.5
> 
> but
> 
> 
>>>>a.__getitem__(0)
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: __getitem__

The quotation above is true. Short form:

IF __getitem__ in dict THEN [] works.

What you are wondering about is the opposite direction

IF [] works THEN __getitem__ in dict.

but this is not what the Python Reference Manual says. Im not a
Numeric expert but AFAIK Numeric arrays are basically C arrays
having [] intrinsically so there's no need no deliver it via
__getitem__.

Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------



More information about the Python-list mailing list