descriptor_instance=MyDescriptor() 当我们运行该代码时,会遇到TypeError: Descriptors cannot be created directly的异常。 二、可能出错的原因 导致TypeError: Descriptors cannot be created directly报错的原因主要有以下几点: 直接实例化描述器:描述器类通常应作为类属性使用,而不是直接实例化。这是因为描述器需要绑定...
TypeError: descriptors cannot be created directly 错误表明你尝试直接实例化了一个应该作为描述符(Descriptor)使用的类。在 Python 中,描述符是一种特殊类型的对象,用于管理对另一个对象的属性访问。它们通常不直接实例化,而是作为类属性存在,并通过类的实例间接访问。
“TypeError: Descriptors cannot not be created directly”主要是由于错误地使用描述符导致的。正确的方式是将描述符作为类属性而不是直接实例化它们。错误使用的本质是违反了描述符用法的基本原则。 一个常见的错误示例: classMyDescriptor:def__get__(self,instance,owner):# 实现相关逻辑 pass # 尝试直接创建描述...
当遇到“TypeError: Descriptors cannot not be created directly”这一错误时,意味着你尝试以错误的方式使用了描述符。记住,描述符应该作为类属性来定义,并通过包含它们的类的实例来触发其行为。正确地理解和应用描述符的概念,可以在Python中实现更加灵活和强大的对象属性管理。希望本文能帮助你理解和解决描述符使用中遇...
“TypeError: Descriptors cannot not be created directly”主要是由于错误地使用描述符导致的。正确的方式是将描述符作为类属性而不是直接实例化它们。错误使用的本质是违反了描述符用法的基本原则。 一个常见的错误示例: class MyDescriptor: def __get__(self, instance, owner): ...
1. 报错信息 TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. 2. 解决方案 点击ternimal输入pip uninstall protobuf将现有版本的卸载,然后输入pip install protobuf 3.19...
TypeError: Descriptors cannot not be created directly这个异常并不是 Python 标准库中的常见异常信息,但它通常与描述符(descriptors)的使用相关。在 Python 中,描述符是一种具有特殊方法的对象属性,这些方法允许描述符对象控制对其值的访问、修改以及可能的其他操作。
TypeError: Descriptors cannot not be created directly. 解决思路 这个错误提示是关于 Protobuf 的,可能是因为你的代码中使用了过时的 Protobuf 版本导致的。 下滑查看解决方法 解决方法 你可以尝试升级 Protobuf 到 3.1.0 或更高版本 或者降级到 3.20.x 或更低版本 ...
问题描述 问题解决 使用如下命令: pip install protobuf==3.12.0 下载更低低版本的protobuf,解决这个版本过高的问题; 亲身试验过,没有任何问题;
TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are:...