1 #!/usr/bin/python
2 # -*- coding:UTF-8 -*-
3
4 class Person():
5 "A Person class"
6
7 def __init__(self,name,age):
8 self.name =name
9 self.__age = age
10
11 def Introduce(self):
12 print "Hi, My name is:%s,I'm %d years-old."%(self.name,self.__age)
13
14
15 class Student(Person):
16 "A student class <- Person"
17
18 def __init__(self,name,age,score):
19 Person.__init__(self,name,age) #Notice:If don't call person.__init__ then Student class will lose name and age.
20 self.score = score
21
22 def ReportScore(self):
23 super(Student,self).Introduce()
24 print "My score is:%d"%(self.score)
25
26 def __str__(self):
27 return "This is a student class"
28
29
30 s1=Student('A',20,80)
31
32 #s1.Introduce()
33 s1.ReportScore()
Error on line 23 of the above code:
➜ Python git:(master) ✗ python oop_syntax.py
Traceback (most recent call last):
File "oop_syntax.py", line 33, in <module>
s1.ReportScore()
File "oop_syntax.py", line 23, in ReportScore
super(Student,self).Introduce()
TypeError: super() argument 1 must be type, not classobj
Reference practice: https://blog.csdn.net/andos/article/details/8973368
Change person to a new class to solve the problem
1 #!/usr/bin/python
2 # -*- coding:UTF-8 -*-
3
4 class Person(object):
5 "A Person class"
6
7 def __init__(self,name,age):
8 self.name =name
9 self.__age = age
10
11 def Introduce(self):
12 print "Hi, My name is:%s,I'm %d years-old."%(self.name,self.__age)
Similar Posts:
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- How to Solve Python TypeError: ‘module’ object is not callable
- Python Typeerror: super() takes at least 1 argument (0 given) error in Python
- [How to Solve]error: invalid array assignment
- MySQL error message: subquery returns more than 1 row and its solution
- Pychar yellow wavy line prompt: simplify chained comparison
- Solutions to errors encountered by Python
- Python scikit-learn (metrics): difference between r2_score and explained_variance_score?
- TypeError: __init__() takes 1 positional argument but 2 were given [How to Solve]
- Python3.x Run Python2.x Codes syntax error: “Missing parentheses in call to ‘print’