dict的一个子类,允许对象样式访问其条目

attribute-dict的Python项目详细描述


属性指令

dict的一个子类,允许对象样式访问其条目。

安装

pipenv install attribute_dict

用法

fromattribute_dictimportAttributeDictsample_dict=AttributeDict({'foo':'bar'})sample_dict# => AttributeDict({'foo': 'bar'})# The object is just subclassed from dict, and has all of the standard functionsisinstance(sample_dict,dict)# => True# Create a new AttributeDict by "stacking" iterables# Each iterable will overwrite keys in the previous one (kwargs are processed last!)sample_dict=AttributeDict({'foo':'foo'},{'foo':'ba','bar':'foo'},{'foo':'bar'},{'foobar':'bar'},foobar='foo')# => AttributeDict({'foo': 'bar', 'bar': 'foo', 'foobar': 'foo'})# Create a new AttributeDict by shallow-copying an existing onenew_sample_dict=sample_dict.copy()new_sample_dict# => AttributeDict({'foo': 'bar', 'bar': 'foo', 'foobar': 'foo'})isinstance(new_sample_dict,AttributeDict)# => True# NOTE: Child values are NOT processed!sample_dict=AttributeDict({'foo':iterable_two})sample_dict# => AttributeDict({'foo': {'foo': 'ba', 'bar': 'foo'}})sample_dict.foo# => {'foo': 'ba', 'bar': 'foo'}sample_dict.__class__.__name__# => 'AttributeDict'sample_dict.foo.__class__.__name__# => 'dict'

测试

测试使用nose2。克隆github项目。安装开发依赖项,并使用nose2命令运行测试。

pipenv install --dev
pipenv shell
nose2

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

推荐PyPI第三方库


热门话题
java Android:应用程序崩溃发送putExtra的意图   JNI错误:尝试传递java实例。字符串作为参数   JavaJMockit与静态初始化   java@products@消费意义。。。JSON或者它只是一个字符串   java如何解决在命令提示符中找不到或加载主类错误?   java使用JavaMail API发送带有内联图像的电子邮件   java为什么我不能与Twitter共享内容   jspservlet正在显示java。木卫一。FileNotFoundException:?E:\guru99\test。txt(文件名、目录名或卷标语法不正确)   java如何在单击另一页上的按钮时向表视图添加数据?   java在提交表单数据之后,它显示了以下问题   java Spring启动通知/严重错误后重启   java从数组列表中删除元素   java Spring引导批处理:如何使用CompositeWriter和自定义ItemWriter实现多线程步骤   Spring java代码表单post和重定向到其他服务器