Blender Python 对象 api:类型方法 return 字符串枚举不是预期的 int
Blender Python object api: Type method return Enum of string not int as expected
我了解 C 中的枚举是什么。
现在我正在 Python.
中编写一个 Blender 插件
本文档中的type
方法
https://docs.blender.org/api/2.78/bpy.types.Object.html
告诉它是 returning 一个 Enum
类型。
但是enum
类型是str
,一个字符串,int
(我的意思是数字)值在哪里?或者这可能是 Python 看待这些事情的方式?
如果这是正确的,文档必须说“return 一个字符串”而不是枚举。
虽然它看起来像是一个奇怪的搅拌机,但根据定义 enumerated type is a set of named values, in C/C++ those values are stored as an int data type, which was probably a decision based on memory usage and performance when comparing them, consider the speed and memory available in 1972 when C was created. The python 3.x standard library has support for enums 类似于您所期望的。
因此,虽然对象类型是可能值的枚举,但所选值存储为字符串,用于对应于 C 源代码中定义的值集合。
部分 blenders 构建过程生成用于 save/load blend 文件的源代码,也用于制作 python 绑定,可以在 blenders C 源代码中找到相关枚举 here, the string located in the second item appears to be the one used for a match in python. If interested start here 了解搅拌机 DNA/RNA.
您可以在搅拌机 python 中找到类似的用法,示例代码 here shows using a bpy.props.EnumProperty
where each enum item is a set of several values. A better example may be using an enum to define a menu, like shown in this answer。
一个类似的怪事是operators的return类型,它是一个集合,集合中的每一项都是一个字符串。我们不只是 return 一个字符串,它需要是一组是字符串对象的项目。
我了解 C 中的枚举是什么。 现在我正在 Python.
中编写一个 Blender 插件本文档中的type
方法
https://docs.blender.org/api/2.78/bpy.types.Object.html
告诉它是 returning 一个 Enum
类型。
但是enum
类型是str
,一个字符串,int
(我的意思是数字)值在哪里?或者这可能是 Python 看待这些事情的方式?
如果这是正确的,文档必须说“return 一个字符串”而不是枚举。
虽然它看起来像是一个奇怪的搅拌机,但根据定义 enumerated type is a set of named values, in C/C++ those values are stored as an int data type, which was probably a decision based on memory usage and performance when comparing them, consider the speed and memory available in 1972 when C was created. The python 3.x standard library has support for enums 类似于您所期望的。
因此,虽然对象类型是可能值的枚举,但所选值存储为字符串,用于对应于 C 源代码中定义的值集合。
部分 blenders 构建过程生成用于 save/load blend 文件的源代码,也用于制作 python 绑定,可以在 blenders C 源代码中找到相关枚举 here, the string located in the second item appears to be the one used for a match in python. If interested start here 了解搅拌机 DNA/RNA.
您可以在搅拌机 python 中找到类似的用法,示例代码 here shows using a bpy.props.EnumProperty
where each enum item is a set of several values. A better example may be using an enum to define a menu, like shown in this answer。
一个类似的怪事是operators的return类型,它是一个集合,集合中的每一项都是一个字符串。我们不只是 return 一个字符串,它需要是一组是字符串对象的项目。