types
— 动态类型的创建和内置类型的名称
¶
源代码: Lib/types.py
此模块定义新类型动态创建的辅助实用函数。
它还定义用于标准 Python 解释器的一些对象类型的名称,但未暴露作为内置像
int
or
str
are.
最后,它提供了一些不够基础内置的额外类型相关实用类和函数。
动态类型的创建 ¶
- 类型。 new_class ( 名称 , bases = () , kwds = None , exec_body = None ) ¶
-
使用适当元类动态创建类对象。
The first three arguments are the components that make up a class definition header: the class name, the base classes (in order), the keyword arguments (such as
metaclass).The exec_body argument is a callback that is used to populate the freshly created class namespace. It should accept the class namespace as its sole argument and update the namespace directly with the class contents. If no callback is provided, it has the same effect as passing in
lambda ns: None.Added in version 3.3.