
python
翠屏阿姨
这个作者很懒,什么都没留下…
展开
-
python 那些待深入理解的东西
class Father:#2.7版本的老式类 def __init__(self): pass def function(self): print(type(self)) print(isinstance(self, Son)) print(isinstance(self, Father)) print(self.mlist) class Son(Father):原创 2017-03-10 00:13:35 · 295 阅读 · 0 评论 -
python 构建一个回调函数
在工作中,回调函数使用的场景是非常多的,下面的例子程序利用了python的属性机制构建了一个回调函数 class Callback: def __init__(self, instance, function_name): self.instance = instance self.function_name = function_name def action(self, par原创 2017-03-11 22:26:22 · 8434 阅读 · 0 评论 -
python 构建一个回调函数2
class Test: def __init__(self): self.f_list = [] def register(self, function): if function in self.f_list: pass else: self.f_list.append(function) def do_test(self): params = []原创 2017-03-11 22:49:08 · 600 阅读 · 0 评论 -
python 继承中的self和__init__
有如下继承关系: #python 2.7 class GrandFather: def __init__(self): print('grandfather') print('---{}\'s __init__ with addr: {}'.format(self.__class__.__name__, self))原创 2017-03-11 23:30:11 · 2051 阅读 · 0 评论 -
python 给生成器发信息
有如下函数: def gen(): li = [1, 2, 3, 4] for i in li: yield i a = gen() try: while True: print(a.next()) except StopIteration: print('generator ({}) has finished.'.format('a')) print(gen) print(原创 2017-03-12 22:55:29 · 315 阅读 · 0 评论 -
python 生成器和lambda的故事
今天在思考python表推导的语法的时候,很好奇这样的结果: a = [ x for x in [1, 2, 3] ] b = ( x for x in [1, 2, 3] ) print('a type: {}'.format(type(a))) print('b type: {}'.format(type(b)))输出: a type: b type: 感觉[和]两个符号表示列表,那么原创 2017-03-14 23:39:50 · 1063 阅读 · 0 评论 -
python 阅读github上某项目所得总结
有如下例子程序 a = [1, 2, 3] b = (1, 2, 3) if isinstance(a, (list, tuple)): print('1.ok') else: print('1.error') if isinstance(b, (list, tuple)): print('2.ok') else: print('2.error') if isinstance(a,原创 2017-03-16 23:04:07 · 874 阅读 · 0 评论