上一页 1 2 3 4 5 6 7 ··· 9 下一页
摘要: class Foo: def __init__(self,n): self.n=n def __iter__(self): return self def __next__(self): if self.n == 13: raise StopIteration('终止了') self.n+=1 re 阅读全文
posted @ 2018-07-26 04:36 一棵大树一棵小树一棵草 阅读(94) 评论(0) 推荐(0) 编辑
摘要: print(a.__doc__)无法继承print(A.__module__)来自哪个模块 print(A.__class__)来自哪个类 class Foo: def __init__(self,name): self.name=name def __del__(self): print('我执行 阅读全文
posted @ 2018-07-26 03:51 一棵大树一棵小树一棵草 阅读(106) 评论(0) 推荐(0) 编辑
摘要: class Foo: __slots__=['name','age'] #{'name':None,'age':None} # __slots__='name' #{'name':None,'age':None}f1=Foo()# f1.name='egon'# print(f1.name)# f1 阅读全文
posted @ 2018-07-25 09:02 一棵大树一棵小树一棵草 阅读(94) 评论(0) 推荐(0) 编辑
摘要: format_dic={ 'ymd':'{0.year}{0.mon}{0.day}', 'm-d-y':'{0.mon}-{0.day}-{0.year}', 'y:m:d':'{0.year}:{0.mon}:{0.day}'}class Date: def __init__(self,year 阅读全文
posted @ 2018-07-25 08:42 一棵大树一棵小树一棵草 阅读(79) 评论(0) 推荐(0) 编辑
摘要: class Foo: pass def __str__(self): return 'shabi' def __init__(self,name,age): self.name=name self.age=age def __str__(self): return '名字是%s 年龄是%s' %(s 阅读全文
posted @ 2018-07-25 08:15 一棵大树一棵小树一棵草 阅读(88) 评论(0) 推荐(0) 编辑
摘要: class Foo: def __getitem__(self, item): print('getitem',item) return self.__dict__[item] def __setitem__(self, key, value): print('setitem') self.__di 阅读全文
posted @ 2018-07-25 07:35 一棵大树一棵小树一棵草 阅读(83) 评论(0) 推荐(0) 编辑
摘要: class Foo: passclass Bar(Foo): passb1=Bar()print(isinstance(b1,Bar))print(isinstance(b1,Foo))print(type(b1))是否子类 class Foo: def __init__(self,x): self 阅读全文
posted @ 2018-07-25 07:06 一棵大树一棵小树一棵草 阅读(108) 评论(0) 推荐(0) 编辑
摘要: import timeclass FileHandle: def __init__(self,filename,mode='r',encoding='utf-8'): # self.filename=filename self.file=open(filename,mode,encoding=enc 阅读全文
posted @ 2018-07-25 06:27 一棵大树一棵小树一棵草 阅读(98) 评论(0) 推荐(0) 编辑
摘要: class List(list): def append(self, p_object): if type(p_object) is str: # self.append(p_object) super().append(p_object) else: print('只能添加字符串类型') def 阅读全文
posted @ 2018-07-25 05:57 一棵大树一棵小树一棵草 阅读(81) 评论(0) 推荐(0) 编辑
摘要: class Foo: x=1 def __init__(self,y): self.y=y def __getattr__(self, item): print(' > from getattr:你找的属性不存在') def __setattr__(self, key, value): print( 阅读全文
posted @ 2018-07-24 08:03 一棵大树一棵小树一棵草 阅读(86) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 9 下一页