__getattitem_ \__setattitem__\__delitem__
class Foo:
def __getitem__(self, item):
print('getitem',item)
return self.__dict__[item]
def __setitem__(self, key, value):
print('setitem')
self.__dict__[key]=value
def __delitem__(self, key):
print('delitem')
self.__dict__.pop(key)
f1= Foo()
print(f1.__dict__)
f1['name']='egon'
f1['age']=19
print('=====>',f1.__dict__)
__getattitem_ \__setattitem__\__delitem__的更多相关文章
- Python的魔法函数之 - __len__,__getitem__,__setitem__,__delitem__
# 对象作为len()函数的参数是必须实现该方法 __len__ # 使用类似字典方式访问成员时必须实现 dic['pro_name'] __getitem__ # 使用类似字典方式设置成员时必须实现 ...
- __delattr__\__delitem__
class Foo: def __init__(self,name): self.name=name def __getitem__(self, item): print(self.__dict__[ ...
- python 魔法方法之:__getitem__ __setitem__ __delitem__
h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...
- python中的__len__,__getitem__ __setitem__ __delitem__ __contains__
可变集合需要实现: __len__ __getitem__ __setitem__ __delitem__不可变集合需要实现: __len__ __getitem__ __len__:返回 ...
- __getitem__ __setitem__ __delitem__ 使用
#__getitem__ __setitem__ __delitem__运行设置key value值了class fun: def __init__(self): print('test') def ...
- 9.4、__del__、__doc__、__dict__、__module__、__getitem__、__setitem__、__delitem__、__str__、__repr__、__call__
相关内容: __del__.__doc__.__dict__.__module__.__getitem__.__setitem__.__delitem__.__str__.__repr__.__cal ...
- __getitem__()、__setitem__()与__delitem__()
# 如果想要运用[]取值,可以实现__getitem__() # 想要运用[]设值,可以实现__setitem__() # 若想通过del与[]来删除,可以实现__delitem__() class ...
- python基础----__setitem__,__getitem,__delitem__
class Foo: def __init__(self,name): self.name=name def __getitem__(self, item): print(self.__dict__[ ...
- Python类,特殊方法, __getitem__,__len__, __delitem__
特殊函数一般以__methodname__的形式命名,如:__init__(构造方法), __getitem__. __setitem__(subscriptable所需method), __deli ...
随机推荐
- Metasploit各版本对比
功能特性 描述 Metasploit Framework Metasploit Community Metasploit Express Metasploit Pro Pricing ...
- [Android]官网《UI/Application Exerciser Monkey》中文翻译
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5049041.html 翻译自 Android Develope ...
- 利用layer的mask属性实现逐渐揭示的动画效果
github上又看到个不错的动画(https://github.com/rounak/RJImageLoader),如图: 所以就想来自己实现以下 不试不知道,这个动画还真不是看上去那么简单,我自己想 ...
- 遇到别人留下的storyboard的,你需要一个引导图,但是不知道怎么跳转.
首先在AppDeledate.m文件里是这样. { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds] ...
- oc 中组合排序算法
- (NSMutableArray *)zuHeSuanFa:(NSMutableArray *)array chooseCount:(int)m { int n = (int)[array coun ...
- 关于UIApplication单例传值
由于UIApplication的是一个系统级别的单例,那么就能够省去自己创建单例的方法,将需要需要的类对象,在UIApplication单例内声明一个,通过点语法来实现单个 需要调用的实现单例模式的类 ...
- MapRedue开发实例
一些例子,所用版本为hadoop 2.6.5 1.统计字数 数据格式如下(单词,频数,以tab分开): A 100 B 97 C 98A 98 package com.mr.test; import ...
- js获取浏览器内核、类型、版本以及系统类型
正则表达式: var rsys = /\b(windows|win32|macintosh|mac os x|adobeair|linux|unix)\b/; var rkn = /\b(opera| ...
- 搭建一个Mongodb (Windows) 版本
因为有项目需要借助nosql 做一个中间层,所以选择了Mongodb 来搞,其实之前呢已经搭建过这部分的环境,这次再次搭建也是记录一下,当时给自己的一个扫盲123教程 借助Mongodb 其实也是缓存 ...
- kattle 发送post请求
一.简介 kattle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,数据抽取高效稳定.它允许你管理来自不同数据库的数据,通过提供一个图形化的用户环境来描述 ...