Janie.Wei
2015-09-11 09:21
采纳率: 0%
浏览 1.7k

python中关于super调用父类构造方法

class Person:
def init(self,n,s):
self.name=n
self.sex=s
print "Person"

class Student(Person):
def init(self,n,s,j):
self.job=j
print "test"
super(Person,self).__init__(n,s)
print "Student"

s=Student("janie","woman","student")

 super那条语句,哪里有问题,为什么报错

 F:\python\python.exe F:/python程序/test.py

Traceback (most recent call last):
File "F:/python程序/test.py", line 17, in
s=Student("janie","woman","student")
File "F:/python程序/test.py", line 13, in init
super(Person,self).__init__(n,s)
TypeError: must be type, not classobj
test

Process finished with exit code 1

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • devmiao 2015-09-12 00:00
    打赏 评论
  • love_chivas 2015-09-12 18:46

    Persion类应该继承object类,是新式类的写法

    打赏 评论
  • 魔力香菇 2015-12-07 06:27

    super的第一个参数是子类,而不是父类。图片说明

    打赏 评论

相关推荐 更多相似问题