会员
周边
众包
新闻
博问
闪存
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
JohnYang
定心者,勇猛精进,终获证果 (知乎:https://www.zhihu.com/people/johnyang819)
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
25
26
27
28
29
2019年3月3日
浅谈Python 中 __getattr__与__getattribute__的区别
摘要: __getattr__与__getattribute__均是一般实例属性截取函数(generic instance attribute interception method),其中,__getattr__可以用在python的所有版本中,而__getattribute__只可以用到新类型类中(Ne
阅读全文
posted @ 2019-03-03 10:27 JohnYang819
阅读(1096)
评论(0)
推荐(0)
2019年3月2日
浅谈__slots__
摘要: __slots__在python中是扮演属性声明(Attribute Declaration)的角色,当然属性本身不用声明,只需要在使用前赋值即可,但是实际上,属性的应用远非在使用前赋值就行,所以有attribute declaration, attribute accessor,attribute
阅读全文
posted @ 2019-03-02 21:47 JohnYang819
阅读(1232)
评论(0)
推荐(1)
__getattr__在python2.x与python3.x中的区别及其对属性截取与代理类的影响
摘要: python2.x中的新类型类(New-style class)与python3.x的类一致,均继承object类,而不继承object的类称为经典类(classic class),而对于这两种类,一般实例属性截取函数(generic instance attribute interception
阅读全文
posted @ 2019-03-02 17:09 JohnYang819
阅读(455)
评论(0)
推荐(0)
2019年2月20日
Python 中异常嵌套
摘要: 在Python中,异常也可以嵌套,当内层代码出现异常时,指定异常类型与实际类型不符时,则向外传,如果与外面的指定类型符合,则异常被处理,直至最外层,运用默认处理方法进行处理,即停止程序,并抛出异常信息。如下代码: try: try: raise IndexError except TypeError
阅读全文
posted @ 2019-02-20 20:53 JohnYang819
阅读(9346)
评论(0)
推荐(0)
2019年2月18日
python 变量搜寻顺序法则LEGB之E注意事项
摘要: 众所周知,在python中,变量不需要事先声明,赋值后,即可调用使用。而调用的法则遵从LEGB法则,其中L为local,E为enclosing,G为Global,B为built-in,即变量首先在局部搜索,比如一个函数中,如果没有搜寻到,则继续在enclosing中搜寻,比如嵌套函数中更靠外侧的函数
阅读全文
posted @ 2019-02-18 20:09 JohnYang819
阅读(548)
评论(0)
推荐(0)
2019年2月7日
%%的一个应用
摘要: 1 """ 2 This script illustrate the usage of escape symbol %%. In general, it is used in mutil-formatted string. when a string is 3 formatted , %% can
阅读全文
posted @ 2019-02-07 14:39 JohnYang819
阅读(161)
评论(0)
推荐(0)
python中__str__与__repr__
摘要: (1)背景 python中,对于类(自定义类)的实例对象的默认显示既没有太大用处,也不美观。比如: 1 class adder: 2 def __init__(self,value=0): 3 self.data=value #初始化数据 4 def __add__(self,other): 5 s
阅读全文
posted @ 2019-02-07 14:27 JohnYang819
阅读(432)
评论(0)
推荐(0)
上一页
1
···
25
26
27
28
29