随笔分类 -  《Mastering Object-oriented Python》

读书笔记
摘要:一:callables 1 import collections.abc #注,完全可以不引入cleection.abc,引入是为了能够做一些错误检查 2 class Power1( collections.abc.Callable ): 3 def __call__( self, x, n ): 阅读全文
posted @ 2016-04-12 15:45 billiepander 阅读(1334) 评论(0) 推荐(0) 编辑
摘要:抽象基本类的几大特点: >>> abs(3) 3 >>> isinstance(abs, collections.abc.Callable) True >>> isinstance( {}, collections.abc.Mapping ) True >>> isinstance( collect 阅读全文
posted @ 2016-04-12 15:04 billiepander 阅读(2214) 评论(0) 推荐(0) 编辑
摘要:一:最基本的属性操作 1 class Generic: 2 pass 3 4 g= Generic() 5 6 >>> g.attribute= "value" #创建属性并赋值 7 >>> g.attribute 8 'value' 9 >>> g.unset 10 Traceback (most 阅读全文
posted @ 2016-04-12 13:58 billiepander 阅读(1010) 评论(0) 推荐(0) 编辑
摘要:1 class Hand: 2 def __init__( self, name, *friends ): 3 self.name = name 4 self.friends= list(friends) 5 6 def __str__( self ): 7 return ", ".join( ma 阅读全文
posted @ 2016-04-12 11:10 billiepander 阅读(2250) 评论(0) 推荐(0) 编辑
摘要:写一个集合类的三种方法:wrap,extend,invent 一:包装一个集合类 三:自行创建 一般用不到,而且很繁琐,有许多特殊方法需要实现 阅读全文
posted @ 2016-04-12 10:01 billiepander 阅读(358) 评论(0) 推荐(0) 编辑
摘要:面对对象编程估计我们最早接触到的就是__init__了,也就是实例的初始化处理过程: 1:来看看最基础的__init__ 2:在子类中使用__init__ 3:没有__init__方法: 完全没有__init__方法的类经常是作为策略类使用,策略类就是把一些列相关操作集合起来的类,通过方法传入的参数 阅读全文
posted @ 2016-04-12 09:21 billiepander 阅读(406) 评论(0) 推荐(0) 编辑
摘要:昨天读完了《Mastering Object-oriented Python》的第一部分,做一些总结。 首先,第一部分总过八章,名字叫Pythonic Classes via Special Methods,也就是讲如何通过特殊方法构造以及设计类的。 其次,第一部分通篇使用的类的例子是BlackJa 阅读全文
posted @ 2016-04-12 07:59 billiepander 阅读(4770) 评论(0) 推荐(0) 编辑