ruby的openstruct for python

pydapt的Python项目详细描述


License: MITcodecovBuild StatusPython 3.7

Pydapt

pydapt将字典转换为对象。 它类似于红宝石的OpenStruct

安装

Python Version Required >= 3
pip install pydapt

用法

将字典转换为对象

frompydapt.modelsimportPyFlexdictionary={"test":1,"test1":{"test2":2}}pyflex=PyFlex(dictionary)print(pyflex.test)# 1print(pyflex.test1.test2)# 2

将字典转换为带kwargs

的对象
frompydapt.modelsimportPyFlexdictionary={"test":1,"test1":{"test2":2}}pyflex=PyFlex(dictionary,test3=3,test4=4)print(pyflex.test)# 1print(pyflex.test1.test2)# 2print(pyflex.test3)# 3print(pyflex.test4)# 4

删除属性

frompydapt.modelsimportPyFlexdictionary={"test":1,"test1":{"test2":2}}pyflex=PyFlex(dictionary)print(pyflex.test)# 1print(pyflex.test1.test2)# 2pyflex.drop('test3')# Nonepyflex.drop('test')# 1print(pyflex.test)# AttributeError: 'PyFlex' object has no attribute 'test'

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

推荐PyPI第三方库


热门话题
相对于框架java窗口的鼠标位置错误   Java 8流peek api   java将数据附加到文件中   java使用ExoPlayer 2.8播放播放列表中的特定文件   JavaSpring国际化:如何动态设置语言环境值   java如何在mysql中实现两个表之间的两个关联   java在gradle可执行jar文件中包含运行时参数   surefire插件中的java maven多套测试套件   java试图理解堆分析以确定内存泄漏或所需的大量内存   java识别字符串有数字   数组如何解决错误“java.lang.ArrayIndexOutOfBoundsException:5”   java Swt文件对话框选择的文件太多?   java此登录代码易受SQL注入攻击吗?   Java[3]中的文件<identifier>预期编译错误   java如何在spring webflux中发送列表   jar中未找到java文件异常   如何在java中合并2D数组?   java如何评测本机JNI库