On Thu, Apr 21, 2011 at 1:21 PM, Alex Companioni <achom...@gmail.com> wrote:
> In the following class definition:
>
> class Tomato(list):
>    def __init__(self, data):
>        list.__init__(self, data)
>
> The list.__init__ method (if it is a method, I'm not clear on what
> __init__ actually *is*) creates a list, right? In other words,
>
> l = Tomato([1,2,3])
>
> will create a list l with the values [1,2,3], correct?

What you actually want is this:

>>> class Tomato(list):
...     def __init__(self, data):
...             super(Tomato, self).__init__(data)
...
>>> l = Tomato([1, 2, 3])
>>> l
[1, 2, 3]
>>>

Your example:

>>> class Tomato(list):
...     def __init__(self, data):
...             list.__init__(data)
...
>>> l = Tomato([1, 2, 3])
>>> l
[]
>>>

Do you see why ?

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to