Question about extending tuple

abcd codecraig at gmail.com
Wed Mar 28 15:32:20 EDT 2007


I wanted to extend tuple but ran into a problem.  Here is what I
thought would work

class MyTuple(tuple):
    def __init__(self, *args):
        tuple.__init__(self, args)

x = MyTuple(1,2,3,4)

That gives me...

TypeError: tuple() takes at most 1 argument (4 given).

However, this call works:

x = MyTuple((1,2,3,4))

I am perplexed only because "args" is a tuple by the definition of
*args.  Anyone?




More information about the Python-list mailing list