【发布时间】:2021-05-17 00:50:00
【问题描述】:
我正在使用 FastAPI 并想为以下请求数据 json 构建一个 pydantic 模型:
{
"gas(euro/MWh)": 13.4,
"kerosine(euro/MWh)": 50.8,
"co2(euro/ton)": 20,
"wind(%)": 60
}
我这样定义模型:
class Fuels(BaseModel):
gas(euro/MWh): float
kerosine(euro/MWh): float
co2(euro/ton): int
wind(%): int
这自然会为wind(%) 提供SyntaxError: invalid syntax。
那么如何为键中包含非字母数字字符的 json 定义 pydantic 模型?
【问题讨论】:
标签: python json fastapi pydantic