标签:recent file setter obj def back port foo import
。。。。。
>>> class Foo(object): def __init__(self,name): self._name = name @property def get_name(self): return self._name >>> f1=Foo(‘yuyang‘) >>> f1.get_name ‘yuyang‘ >>> f1.get_name = ‘dfd‘ Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> f1.get_name = ‘dfd‘ AttributeError: can‘t set attribute
大概VC
>>> class Foo(object): def __init__(self,name): self._name = name @property def get_name(self): return self._name @get_name.setter def get_name(self,value): self._name = value >>> f2=Foo(‘yuyagng‘) >>> f2.get_name ‘yuyagng‘ >>> f2.get_name = ‘alex‘ >>> f2.get_name ‘alex‘
收费电视
>>> class Foo(object): def __init__(self,name): self._name = name def get_name(self): return self._name def set_name(self,value): self._name = value property(get_name,set_name) >>> f3 = Foo(‘dsadsa‘) >>> f3.get_name <bound method Foo.get_name of <__main__.Foo object at 0x0000000002F13EF0>> >>> f3.get_name() ‘dsadsa‘ >>> f3.set_name(‘wupeiqi‘) >>> f3.get_name() ‘wupeiqi‘ >>> class Foo(object): def __init__(self,name): self._name = name def get_name(self): return self._name def set_name(self,value): self._name = value name = property(get_name,set_name) >>> f3 = Foo(‘dsadsa‘) >>> f3.get_name() ‘dsadsa‘ >>> f3.name = ‘laoda‘ >>> f3.get_name() ‘laoda‘
VC下
vc
>>> class Mycalss(object): d={‘a‘:1,‘b‘:2,‘c‘:3} def __getitem__(self,value): return self.d[value] def __setitem__(self,key,value): self.d[key] = value >>> myclass = Myclass() Traceback (most recent call last): File "<pyshell#23>", line 1, in <module> myclass = Myclass() NameError: name ‘Myclass‘ is not defined >>> myclass = Mycalss() >>> myclass[‘a‘] 1 >>> myclass[‘b‘] 2 >>> myclass[‘f‘]=4 >>> myclass[‘f‘] 4 >>> myclass[‘a‘]=‘aaaa‘ >>> myclass[‘a‘] ‘aaaa‘
import base64 >>> a= ‘asdasdfas‘ >>> a2 =a.encode(‘utf-8‘) >>> a64 = base64.b64encode(a2) >>> a2 b‘asdasdfas‘ >>> a64 b‘YXNkYXNkZmFz‘ >>> base64.b64encode(a64) b‘WVhOa1lYTmtabUZ6‘ >>> a64 b‘YXNkYXNkZmFz‘ >>> base64.b64decode(a64) b‘asdasdfas‘ >>> a64.decode(‘utf-8‘) ‘YXNkYXNkZmFz‘ >>> a64_de = base64.b64decode(a64) >>> a64_de b‘asdasdfas‘
标签:recent file setter obj def back port foo import
原文地址:http://www.cnblogs.com/yuyang26/p/7857463.html