python中marshmallow库如何使用

369次阅读
没有评论

python中marshmallow库如何使用

概念

1、是专门用来支持 Python 对象和原生数据相互转换的库,如实现 object -> dict,objects -> list, string -> dict, string -> list 等的转换功能。

2、提供了非常丰富的数据类型转换和校验 API,帮助我们快速实现数据的转换。

实例

调用 Schema 的 load 事件:

schema = UserSchema()
users = schema.load(data, many=True)
print(users)

输出结果:

[User(name='Germey', age=23), User(name='Mike', age=20)]
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-07-05发表,共计298字。
新手QQ群:570568346,欢迎进群讨论 Python51学习