Python错误:继承了'X',这不是一个类

问题描述 投票:0回答:1

我已经在VS代码上写了thad代码

from datetime import date

Title = 'Actividad #$'
Complexity = 0
Time = 5 #cantidad en dias

class Activitie(Title,Complexity,Time):
    """Log your activity with this class"""

    Title = 'Actividad #$'
    Complexity = 0
    Time = 5 #cantidad en dias

它显示

Inheriting 'Time', which is not a class.
Inheriting 'Complexity', which is not a class.
Inheriting 'Title', which is not a class.

和...

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

感谢您提供任何解决方案

请原谅我的英语:V

python oop inheritance pylint
1个回答
0
投票

看起来您想定义类对象构造函数,但是您偶然使用Python的类继承语法来完成它。

这里是定义类及其对象构造函数的方法:

class Activitie:
    def __init__(self, Title, Complexity, Time):
    """Log your activity with this class"""

        self.Title = Title
        self.Complexity = Complexity
        self.Time = Time 

您收到此继承错误,是因为在Python中声明继承的语法如下:

SubClass(ParentClassA, ParentClassB, ParentClassC):
© www.soinside.com 2019 - 2024. All rights reserved.