overriding a tuple's __init__

Andrew Dalke adalke at mindspring.com
Mon Aug 18 20:08:59 CEST 2003


Aahz:
> class pair(tuple):
>     def __new__(cls, *args):
>         return tuple.__new__(cls, args)

Right.  cls instead of self because it isn't passed the instance.

It would help me learn this new part of Python if I had
any use for it.  :)

Though *args likely isn't what the OP wanted - I assume
that 'pair' takes only two elements.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list