Python自生

python-autoviv的Python项目详细描述


python autovivPyPiPyPiStats

Python的自生库

安装

将此行添加到应用程序的要求.txt公司名称:

python-autoviv

然后执行:

^{pr2}$

或自行安装为:

$ pip install python-autoviv

使用

导入autoviv并对任何list、dict或基元调用parse。还可以调用序列化JSON上的加载

>>>importautoviv>>>importrequests>>>r=requests.get('http://jsonplaceholder.typicode.com/users')>>>users=autoviv.parse(r.json())>>># or...users=autoviv.loads(r.text)>>>foruserinusers:...print(user.name)...LeanneGrahamErvinHowellClementineBauchPatriciaLebsackChelseyDietrichMrs.DennisSchulistKurtisWeissnatNicholasRunolfsdottirVGlennaReichertClementinaDuBuque>>>user=users[0]>>>print(autoviv.pprint(user,indent=4)){"username":"Bret","website":"hildegard.org","name":"Leanne Graham","company":{"bs":"harness real-time e-markets","name":"Romaguera-Crona","catchPhrase":"Multi-layered client-server neural-net"},"id":1,"phone":"1-770-736-8031 x56442","address":{"suite":"Apt. 556","street":"Kulas Light","geo":{"lat":"-37.3159","lng":"81.1496"},"zipcode":"92998-3874","city":"Gwenborough"},"email":"Sincere@april.biz"}>>>user.name='auto-vivification'>>>r=requests.put('http://jsonplaceholder.typicode.com/users/{0}'.format(user.id),json=user)>>>response=autoviv.parse(r.json())>>>print(response.name)auto-vivification>>>new=autoviv.parse({})>>>new.id=5>>>ifnotnew.username:...new.username='New User'...>>>new.address.geo.lat="-42.3433">>>new.address.geo.lng="74.3433">>>new.email='someone@somewhere.biz'>>>print(autoviv.pprint(new)){"username":"New User","email":"someone@somewhere.biz","id":5,"address":{"geo":{"lat":"-42.3433","lng":"74.3433"}}}

非prop

应该注意的是,缺少引用的属性,包括嵌套的属性,都是错误的。在

>>>importautoviv>>>data=autoviv.parse({})>>>data.property.is_none>>>bool(data.property.is_none)False>>>isinstance(data.property.is_none,autoviv.NoneProp)True>>>'some data'indata.property.is_noneFalse>>>[xforxindata.property.is_none][]>>>data.property.is_none=None>>>isinstance(data.property.is_none,autoviv.NoneProp)False>>>print(autoviv.pprint(data)){"property":{"is_none":null}}

测试

使用pipenv安装测试依赖项。在

$ pip install pipenv
$ pipenv install -d
$ ./test.sh

贡献

欢迎在GitLab的https://gitlab.com/tysonholub/python-autoviv.git上提交错误报告和请求。这个项目是 旨在成为一个安全、受欢迎的协作空间,并且贡献者应遵守 Contributor Covenant行为准则。在

许可证

根据MIT License的条款,这个包是开源的。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何修复尝试将用户签名到服务器主机时出现的“字符串无法转换为json对象”错误?   控制台Java:不使用新行更新命令行中的文本   java servlet接收xml数据时,出现错误   使用REST API在Bitbucket中复制或复制存储库   java如何在JavaFX中对齐一行?   java如何在活动中显示通过服务获得的数据?   返回BigDecimal作为字符串:返回int   java组织。openqa。硒。InvalidSelectorException:尝试查找元素时选择器无效   java仅在阻塞状态下通知和通知所有影响线程   java JBOSS无法启动部署   java方法的返回值能保证类型安全吗?   JavaeShadoop序列化组织。阿帕奇。hadoop。木卫一。短写失败   java如果我在同一个类上同步了两个方法,它们能同时运行吗?   不使用java数据库的spring分页实现   java如何将字符串切碎成这样的数组?