Initializing subclasses of tuple

Dave Opstad dave.opstad at monotypeimaging.com
Tue Mar 1 17:01:33 CET 2005


I'm hoping someone can point out where I'm going wrong here. Here's a 
snippet of a Python interactive session (2.3, if it makes a difference):

--------------------------------------
>>> class X(list):
...   def __init__(self, n):
...     v = range(n)
...     list.__init__(self, v)
... 
>>> x = X(10)
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> class Y(tuple):
...   def __init__(self, n):
...     v = tuple(range(n))
...     tuple.__init__(self, v)
... 
>>> y = Y(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: iteration over non-sequence
--------------------------------------

How do I initialize instances of a class derived from tuple, if it's not 
in the __init__ method?

Thanks for any help!
Dave Opstad



More information about the Python-list mailing list