python - 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
感谢您提供任何解决方案
解决方案
看起来您想要定义类对象构造函数,但您不小心使用 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):
推荐阅读
- git - Jenkins Git 插件客户端不使用发布者的凭据
- javascript - 如何更改蜘蛛网图表中单点的颜色
- python - 如何使硒浏览器和手动打开的浏览器具有相同的行为?
- python - 如何使用新鲜番茄模板将数据从 excel 文件导入和读取到 Python 电影中心
- amazon-web-services - API Gateway 中 AWS Firehose PutRecordBatch 的映射模板应该是什么样的?
- java - 当您在 Firebase 上使用 .setPersistenceEnabled(true) 时,真的需要 .addOnCompleteListener 吗?
- c++ - 这种使用联合的类型别名是否会调用未定义的行为?
- node.js - Node.js 如何压缩图像数组并强制浏览器下载
- amazon-ec2 - nfs 目录始终以只读方式挂载,但 /etc/fstab 具有 rw 选项
- c# - 在 TextBox 中只允许 1 个符号