using super

S

sashan

I'm trying to use super but keep getting the following error

E:\Code\Python\Nexus\Player>python ./super_test.py
Traceback (most recent call last):
File "./super_test.py", line 14, in ?
main()
File "./super_test.py", line 11, in main
b = B()
File "./super_test.py", line 7, in __init__
super(B, self).__init()
TypeError: super() argument 1 must be type, not classobj

Here's the code:
class A:
def __init__(self):
print 'A'

class B(A):
def __init__(self):
super(B, self).__init()
print 'B'

def main():
b = B()

if __name__ == '__main__':
main()
 
M

Matt Goodall

sashan said:
I'm trying to use super but keep getting the following error

E:\Code\Python\Nexus\Player>python ./super_test.py
Traceback (most recent call last):
File "./super_test.py", line 14, in ?
main()
File "./super_test.py", line 11, in main
b = B()
File "./super_test.py", line 7, in __init__
super(B, self).__init()
TypeError: super() argument 1 must be type, not classobj

Here's the code:
class A:
def __init__(self):
print 'A'
class B(A):
def __init__(self):
super(B, self).__init()
print 'B'
def main():
b = B()
if __name__ == '__main__':
main()

super() only works for "new style" classes, that is classes that extend
Python's object type. class A(object) should solve your problem.

Cheers, Matt
 
P

Paul McGuire

Here's the code:

You will also need to correct:
super(B, self).__init()
to read
super(B, self).__init__()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,915
Members
47,456
Latest member
JavierWalp

Latest Threads

Top