Python-list Info Page

Gary Robinson grobinson at transpose.com
Sat Oct 30 23:43:40 EDT 2004


I am trying to understand a couple of nuances of inheriting from the 
tuple type.

The following class definition works nicely:

class Test(tuple):
    def __init__(self, tup):
        self.x = 5
        self = tup        
a = Test((1,2))
print a, a.x

The result of that print is "(1, 2), 5". 

But the following version:

class Test(tuple):
    def __init__(self, tup):
        self = tup
        self.x = 5
a = Test((1,2))

blows up in Python 2.3, complaining that attribute x doesn't exist.

I'm not clear on why one works and not the other, or whether there's a 
better syntax for assigning an attribute to a tuple subclass in the 
__init__() method.

Anyone have any  thoughts??

Gary
-- 

Gary Robinson
CEO
Transpose, LLC
grobinson at transpose.com
207-942-3463
Company: http://www.transpose.com
Blog:    http://www.garyrobinson.net



More information about the Python-list mailing list