Python
文章平均质量分 52
chimuuu
https://github.com/chimuuu
展开
-
python中 正则表达式匹配一个反斜杠 ‘\’
# coding:utf-8 import re re_str = "\\\\" # reObj = re.compile(restr) test_str = "abc\\cd\\hh" res = re.findall(re_str, test_str) print res for i in res: print i 结果为: ['\\', '\\'] \ \原创 2017-08-13 19:56:04 · 1618 阅读 · 0 评论 -
Python类中实例方法、类方法及静态方法的调用区别
# usr/bin/env python # _*_ coding:utf-8 _*_ ''' 测试python类中: 实例方法,类方法,静态方法及普通方法的调用方法区别 结论 1. instance创建时包含隐藏参数self,cls.因此调用时对四种method皆可直接调用; 2. class创建时包含隐藏参数cls.无self. 因此调用instance_method时需要传入instanc原创 2017-09-17 09:31:19 · 4052 阅读 · 2 评论 -
Python 装饰器实现样例
# coding:utf-8 ''' 装饰器实现 闭包的应用 装饰器和被装饰函数都有参数时, 一:需要三层的嵌套 第一层传装饰器参数、第二层嵌套传函数、第三层传被装饰函数的参数 二:三层返回 最里层返回func(*args)拿到参数,外层返回最里层函数,最外层返回次外层 ''' def dec(isnot = False): print 'call dec' if isnot:原创 2017-09-12 21:21:21 · 420 阅读 · 0 评论