"James Mills" <prolo...@shortcircuit.net.au> wrote

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 ?

This confuses things (at least for me!) It has nothing to do with the use of super() but all to do with the use of self.

The OPs style works fuine with self:

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


Using super may be the prefered way of calling the superclass but its not the reason the OP code didn't work.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to