- BaseModel
from pydantic import BaseModel
# 定义类
class User(BaseModel):
id: int
name:str
sex:str
age:int
def myFunc(self):
pass
# =======================================
# 字典数据
external_data = {
'id': 1,
'name':'周星驰',
'sex':'男',
'age':'18',
}
# 字典数据转类(类实例化)
userClass = User(**external_data)
# 类转字典数据
userDict = userClass.dict()
__slots__
class test(object): #定义一个类。
__slots__ = ('name','age')