![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python代码学习
文章平均质量分 62
Qing_擎
菜鸟运维
展开
-
getattr用法
class result(): a=100 def text(self): b=20 return b if __name__=='__main__': t=result() result1=getattr(t,'text')() result2=getattr(t,'a','default') result3=getattr(t,'b','default') pr原创 2014-08-18 15:30:39 · 237 阅读 · 0 评论 -
random.randint
import random class result: def choicename(self): list=['a','songchen','muzhou'] for i in list: if i==list[0]: result=random.randint(90,100)原创 2014-08-20 11:45:59 · 389 阅读 · 0 评论 -
python中re的使用
''' Creat by Qing 2014-08-21 ''' import urllib2 import urllib import re import bs4 headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} url原创 2014-08-21 11:23:01 · 303 阅读 · 0 评论 -
python装饰器
“装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志、性能测试、事务处理等。装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同代码并继续重用。概括的讲,装饰器的作用就是为已经存在的对象添加额外的功能。” 举例: def deco(func): def wrapper(*args,**kwargs):原创 2015-01-04 14:43:58 · 229 阅读 · 0 评论