会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
狂奔~
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
30
31
32
33
34
35
36
37
38
···
41
下一页
2019年3月4日
异常处理(四十二)
摘要: 转自:http://www.cnblogs.com/linhaifeng/articles/6232220.html 异常就是程序运行时发生错误的信号(在程序出现错误时,则会产生一个异常,若程序没有处理它,则会抛出该异常,程序的运行也随之终止) 异常处理的作用: 1.可以把错误处理和真正的工作分开来
阅读全文
posted @ 2019-03-04 09:50 狂奔~
阅读(328)
评论(0)
推荐(0)
2019年3月3日
元类(四十一)
摘要: http://www.cnblogs.com/linhaifeng/articles/8029564.html 元类: 一切源自于一句话:python中一切皆为对象。 如果一切皆为对象,那么类People本质也是一个对象,既然所有的对象都是调用类得到的,那么People必然也是调用了一个类得到的,这
阅读全文
posted @ 2019-03-03 20:52 狂奔~
阅读(184)
评论(0)
推荐(0)
property(四十)
摘要: 一个静态属性property本质就是实现了get,set,delete三种方法 用法: class Foo: @property def AAA(self): print('get的时候运行我啊') @AAA.setter def AAA(self,value): print('set的时候运行我啊
阅读全文
posted @ 2019-03-03 19:40 狂奔~
阅读(115)
评论(0)
推荐(0)
描述符和类的装饰器(三十九)
摘要: 简单实现 加强版 应用: 描述符总结 描述符是可以实现大部分python类特性中的底层魔法,包括@classmethod,@staticmethd,@property甚至是__slots__属性 描述父是很多高级库和框架的重要工具之一,描述符通常是使用到装饰器或者元类的大型框架中的一个组件.
阅读全文
posted @ 2019-03-03 17:48 狂奔~
阅读(258)
评论(0)
推荐(0)
上下文管理协议with_open,__enter__和__exit__(三十八)
摘要: 在操作文件对象的时候可以这么写 上述叫做上下文管理协议,即with语句,为了让一个对象兼容with语句,必须在这个对象的类中声明__enter__和__exit__方法 with obj as f 等同于 f = obj.__enter__() __exit__()中的三个参数分别代表异常类型,异常
阅读全文
posted @ 2019-03-03 15:36 狂奔~
阅读(220)
评论(0)
推荐(0)
描述符__get__(),__set__(),__delete__()(三十七)
摘要: http://www.cnblogs.com/linhaifeng/articles/6204014.html#_label12 描述符是什么:描述符本质就是一个新式类,在这个新式类中,至少实现了__get__(),__set__(),__delete__()中的一个,这也被称为描述符协议 __ge
阅读全文
posted @ 2019-03-03 08:16 狂奔~
阅读(199)
评论(0)
推荐(0)
2019年3月2日
__slots__,__doc__,__del__,__call__,__iter__,__next__迭代器协议(三十六)
摘要: __doc__ __module__ 表示当前操作的对象在那个模块 __class__ 表示当前操作的对象的类是什么 from lib.aa import Test t = Test() print(t.__module__) # lib.aa print(t.__class__) # <class
阅读全文
posted @ 2019-03-02 22:54 狂奔~
阅读(213)
评论(0)
推荐(0)
isinstance和issubclass,__getattribute__,__getitem__,__setitem__,delitem__,__str__(三十五)
摘要: isinstance(obj,cls)检查是否obj是否是类 cls 的对象 issubclass(sub, super)检查sub类是否是 super 类的派生类 __getattribute__ 当__getattribute__与__getattr__同时存在,只会执行__getattrbut
阅读全文
posted @ 2019-03-02 22:44 狂奔~
阅读(150)
评论(0)
推荐(0)
包装标注类型(三十四)
摘要: 来源: http://www.cnblogs.com/linhaifeng/articles/6204014.html#_label3 包装:python为大家提供了标准数据类型,以及丰富的内置方法,其实在很多场景下我们都需要基于标准数据类型来定制我们自己的数据类型,新增/改写方法,这就用到了继承/
阅读全文
posted @ 2019-03-02 17:57 狂奔~
阅读(240)
评论(0)
推荐(0)
面向对象——类的内置attr(三十三)
摘要: 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 @ 2019-03-02 17:02 狂奔~
阅读(179)
评论(0)
推荐(0)
上一页
1
···
30
31
32
33
34
35
36
37
38
···
41
下一页
公告