品易云推流 关闭
文章详情页
文章 > Python基础教程 > python中marshmallow库如何使用

python中marshmallow库如何使用

Python marshmallow

头像

小妮浅浅

2021-08-03 09:55:302355浏览 · 0收藏 · 0评论

概念

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)]

以上就是python中marshmallow库的使用,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图