calling super()

John Clark clajo04 at mac.com
Wed Apr 4 15:30:53 EDT 2007


Yeah!!! One I can actually answer!!!

super() only works on new-style classes - your classes don't have object
anywhere in the inheritance tree so super() isn't going to help..

New-style classes are known as types, old-style classes are known as
classobjs.

Hope this helps,
-jdc


-----Original Message-----
From: python-list-bounces+clajo04=mac.com at python.org
[mailto:python-list-bounces+clajo04=mac.com at python.org] On Behalf Of
Finger.Octopus at gmail.com
Sent: Wednesday, April 04, 2007 3:23 PM
To: python-list at python.org
Subject: calling super()

Hello, I have been trying to call the super constructor from my derived
class but its not working as expected. See the code:

class HTMLMain:
    def __init__(self):
        self.text = "<HTML><BODY>";
        print(self.text);
    def __del__(self):
        self.text = "</BODY></HTML>";
        print(self.text);

class NewPage(HTMLMain):
    def __init__(self):
        print 'derive2 init'
        super(NewPage, self).__init__();


N = NewPage();
del N


And here's the error message I get:

Traceback (most recent call last):
  File "e:/PyEN/inherit.py", line 16, in <module>
    N = NewPage();
  File "e:/PyEN/inherit.py", line 12, in __init__
    super(NewPage, self).__init__();
TypeError: super() argument 1 must be type, not classobj

--
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list