Re: Python-list Info Page

From: Gary Robinson (grobinson_at_transpose.com)
Date: 10/31/04


Date: Sat, 30 Oct 2004 23:43:40 -0400
To: python-list@python.org

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@transpose.com
207-942-3463
Company: http://www.transpose.com
Blog:    http://www.garyrobinson.net