staticmethod,classmethod
来源:互联网 发布:c语言读取字符串 编辑:程序博客网 时间:2024/06/09 15:02
#/usr/bin/python## Author:Tom# Date:2017/04/22# Email:bluelovelydog@gmail.com#class A: """ this class is test api for python """ def __init__(self, name, age): self.name = name self.age = age @property def name(self): return self.name @name.setter def name(self, value): self.name = value @property def name(self): return self.age @classmethod def get_ome(cls, val): for i in val: yield i or None @staticmethod def get_o(val): for i in val: yield i or Noneif __name__ == '__main__': # a = A(1,2) # a.name = 10 # print (a.name) # m = a.get_ome([1,2,3,4,5]) # print(m.next()) # print (m.send(0)) # print (m.send(1)) # test for classmethod # m = A.get_ome([1,2,3,4,5,6,7,8]) # m.next() # for i in range(8): # try: # print (m.send(i)) # except StopIteration: # ValueError(u'u') # test for classmethod m = A(1,2) q = m.get_ome([1,2,3,4]) q.next() print (q.send(0)) print (q.next()) # test for staticmethod # n = A.get_o([1,2,3,4]) # n.next() # print (n.send(0)) # test for staticmethod # a = A(1,2) # t = a.get_o([1,2,3,4,5]) # t.next() # print (t.send(0))
类名不要用数字,否则你无法在shell里import模块
都可以通过实例化类来调用classmethod,staticmethod
也都可以通过类名直接调用classmethod,staticmethod
第一步
>>> dir(a)
['A', '__builtins__', '__doc__', '__file__', '__name__', '__package__']
>>>
第二步
>>> dir(A)
['__doc__', '__init__', '__module__', 'get_o', 'get_ome', 'name']
>>>
0 0
- staticmethod,classmethod
- classmethod、staticmethod
- Python: classmethod & staticmethod 区别
- @staticmethod和@classmethod
- Python: classmethod & staticmethod 区别
- 】Python @classmethod @staticmethod
- python staticmethod和classmethod
- python classmethod staticmethod
- Python @staticmethod和@classmethod
- 有关staticmethod classmethod
- Python @classmethod @staticmethod
- python的staticmethod、classmethod
- Python staticmethod and classmethod
- 【转】Python @classmethod @staticmethod
- python staticmethod & classmethod
- python @ property classmethod staticmethod
- Python: classmethod & staticmethod 区别
- python classmethod,staticmethod实现
- 内核是如何管理内存的
- windows7 64位 配置 python2.7 开发环境
- 关于typedef用法总结【待补充】
- Android TV书签
- canvas合成
- staticmethod,classmethod
- 第一篇、Android学习之AIDL学习:跨应用启动服务Serivce
- JavaScript Ajax和jQuery Ajax
- BZOJ 1297 1297: [SCOI2009]迷路 拆点,矩阵快速幂
- PowerDesigner导出SQL添加视图的方法
- PCI 总线 协议 基础 详解
- JavaWeb日记——Shiro之角色和权限
- CCF NOI1036 进制转换
- xListView--MylistViewDemo--1