首页 > 解决方案 > Python错误:继承'X',它不是一个类

问题描述

我已经使用 Visual Studio 代码编写了代码

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

感谢您提供任何解决方案

标签: pythonoopinheritancepylint

解决方案


看起来您想要定义类对象构造函数,但您不小心使用 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):

推荐阅读