会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
JohnYang
定心者,勇猛精进,终获证果(https://johnsite.157489.xyz/)
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
26
27
28
29
30
2019年3月8日
装饰器之技术小总结
摘要: 装饰器的作用是在已有的可调对象(callable object)的基础上,插入代码,以增强或者管理可调对象,装饰器的核心就是通过传入一个可调对象,然后返回一个可调对象,就其装饰的对象而言,可以分为函数装饰器和类装饰器,就其构造方法而言,可以用嵌套函数(nested functions)或者类方法。
阅读全文
posted @ 2019-03-08 11:37 JohnYang819
阅读(247)
评论(0)
推荐(0)
2019年3月5日
浅谈Python之sys.argv
摘要: (1)sys.argv是什么 sys模块为进入解释器维护或使用的变量,以及与解释器相关的函数提供了途径。sys.argv在脚本程序中扮演了这样一个角色:将命令行输入的参数作为一个list传入脚本程序,即我们可以在cmd命令形式驱动程序方法下,将设定的参数传入脚本,argv[0]是驱动脚本的名字(由操
阅读全文
posted @ 2019-03-05 21:30 JohnYang819
阅读(641)
评论(0)
推荐(0)
2019年3月3日
浅谈Python 中 __getattr__与__getattribute__的区别
摘要: __getattr__与__getattribute__均是一般实例属性截取函数(generic instance attribute interception method),其中,__getattr__可以用在python的所有版本中,而__getattribute__只可以用到新类型类中(Ne
阅读全文
posted @ 2019-03-03 10:27 JohnYang819
阅读(1100)
评论(0)
推荐(0)
2019年3月2日
浅谈__slots__
摘要: __slots__在python中是扮演属性声明(Attribute Declaration)的角色,当然属性本身不用声明,只需要在使用前赋值即可,但是实际上,属性的应用远非在使用前赋值就行,所以有attribute declaration, attribute accessor,attribute
阅读全文
posted @ 2019-03-02 21:47 JohnYang819
阅读(1239)
评论(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
阅读(459)
评论(0)
推荐(0)
2019年2月20日
Python 中异常嵌套
摘要: 在Python中,异常也可以嵌套,当内层代码出现异常时,指定异常类型与实际类型不符时,则向外传,如果与外面的指定类型符合,则异常被处理,直至最外层,运用默认处理方法进行处理,即停止程序,并抛出异常信息。如下代码: try: try: raise IndexError except TypeError
阅读全文
posted @ 2019-02-20 20:53 JohnYang819
阅读(9360)
评论(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
阅读(557)
评论(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
阅读(164)
评论(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
阅读(439)
评论(0)
推荐(0)
上一页
1
···
26
27
28
29
30