Operator Overloading

Nick Coghlan ncoghlan at email.com
Thu Nov 25 08:39:18 EST 2004


Peter Maas wrote:
> 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__.

This is correct, and true of any C extension - classes implemented in C only 
need to define the appropriate function pointers in their type structures in 
order for Python to find the relevant methods.

Classes that are being *nice* about it put in the actual magic method names as 
well (e.g. try "list.__getitem__"), but it is by no means required.

Cheers,
Nick.



More information about the Python-list mailing list