小编SUB*_*NDA的帖子

TypeError:描述符'__init__'需要'超级'对象但收到'str'

使用Python 3.X作为解释器.我刚刚继承了Employee两个派生类的类作为DeveloperManager.

下面的代码抛出了一个类型错误: '__init__' requires a 'super' object but received a 'str'.
我不知道为什么会发生这种情况,我还没有发现该程序有任何问题.

class Employee:
    raise_amount=1.05
    emp_count=0
    def __init__(self,first_name,last_name, amount):
        self.first_name=first_name
        self.last_name=last_name
        self.amount=amount
        self.email_id="{0}.{1}@{1}.com" .format(first_name,last_name)
        Employee.emp_count +=1

    def fullname(self):
        print ("%s %s"%(self.first_name,self.last_name))

    def print1(self):
        print (self.email)
        print ("Total no of Employee are :%d" %(Employee.emp_count))


    def raise_amount(self):
        self.amount *=self.raise_amount
        return self.amount


class Developer(Employee):
    raise_amount = 1.10
    def __init__(self,f,l,a,prog):
        super.__init__(f,l,a)
        self.programming=prog

class Manager(Employee):
    def __init__(self,f,l,a,emp=None):
        super.__init__(f,l,a)
        if emp is None:
            self.my_employee=[]
        else:
            self.my_employee=emp



    def add_employee(self,emp): …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x

4
推荐指数
3
解决办法
6793
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1