按类别查询搜索结果
关于关键词 的检测结果,共 880
shibeng752 | 2019-03-25 22:05:40 | 阅读(5771) | 评论(0)
873313579 | 2019-03-25 14:01:33 | 阅读(9820) | 评论(0)
class Test(object):def InstanceFun(self): print("InstanceFun"); print(self);@classmethoddef ClassFun(cls): print("ClassFun"); print(cls);@staticmethoddef StaticFun(): print("StaticFun"); t = Test(); t.InstanceFun();      # 输出InstanceFun,打印对象内存地址...【阅读全文】
可怜的猪头 | 2019-03-19 13:59:35 | 阅读(1730) | 评论(0)
[root@localhost /]# [root@localhost /]# [root@localhost /]# cat z.py #!/bin/pythonfrom functools import update_wrapper, wrapsdef a(b,c=3,d=[]):        '''aaaaaaaaaaaaaa'''    return a*2#print a.__name__#print a.__defaults__#print a.__doc__...【阅读全文】
可怜的猪头 | 2019-03-18 15:45:36 | 阅读(7530) | 评论(0)
修饰器,增加缓存的意义[root@localhost /]# [root@localhost /]# cat zlg.py #!/bin/pythondef a(n,cache=None):    if cache is None:        cache={}    if n in cache:        return cache[n]   ...【阅读全文】
可怜的猪头 | 2019-03-18 14:48:31 | 阅读(1900) | 评论(0)
转自:https://blog.csdn.net/pro_leo/article/details/41786397(有修订)1、Python缓存作用:  a、提高执行效率。  b、减少内存负担。2、首先,我们看下面这一段code:>>> num1, num2 = 1, 1 >>> print num1 is num2 True >>> id(num1), id(num2) (3965416, 3965416) >>> num...【阅读全文】
可怜的猪头 | 2019-03-15 11:10:12 | 阅读(4730) | 评论(0)
首先,如果你还没有对yield有个初步分认识,那么你先把yield看做“return”,这个是直观的,它首先是个return,普通的return是什么意思,就是在程序中返回某个值,返回之后程序就不再往下运行了。看做return之后再把它看做一个是生成器(generator)的一部分(带yield的函数才是真正的迭代器),好了,如果你对这些不明白...【阅读全文】
可怜的猪头 | 2019-03-14 16:50:12 | 阅读(890) | 评论(0)
http://www.cnblogs.com/rollenholt/archive/2012/05/02/2479833.html装饰器:函数的扩展,函数作为参数传递装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志、性能测试、事务处理等。装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷...【阅读全文】
【LINUX】 python librtmp
zds05 | 2019-03-13 17:26:28 | 阅读(0) | 评论(0)
git clone git://github.com/chrippa/python-librtmp.gitcd rtmpdump/make installsudo python setup.py install/usr/lib64/python2.7/site-packages/python_librtmp-0.3.0-py2.7-linux-x86_64.egg/librtmp/ldd _librtmp.so cp /usr/local/lib/librtmp.so.1 /lib64/【阅读全文】
可怜的猪头 | 2019-03-13 15:13:55 | 阅读(4600) | 评论(0)
数量词{1,2}非贪婪{1,2}?* 号 前面的字符匹配0次或无限多次+号 前面的字符匹配一次或无限多次?号前面的字符匹配0次或一次边界匹配^    $以上都是指的字符,下面介绍组组的概念()[root@localhost /]# cat str.py #!/bin/pythonimport rea='python 1111java678php'b=re.findall('[a-z]{3,6}?',a...【阅读全文】
可怜的猪头 | 2019-03-07 11:05:22 | 阅读(2640) | 评论(0)
[root@localhost /]# [root@localhost /]# cat zlg.py #!/bin/pythonfrom random import randintimport timemylist=[1,2,3,4]mylist.reverse()for x in mylist:    print xmytuple=(1,2,3,4)for y in range(len(mytuple)-1,-1,-1):    print mytuple[y]mystr='hello you are a b...【阅读全文】
可怜的猪头 | 2019-03-06 16:33:52 | 阅读(1610) | 评论(0)
1.如何反向迭代一个序列2.如何查询和替换一个文本中的字符串3.使用python实现单例模式4.重新实现str.strip()5.闭包6.给列表中的字典排序7.合并两个列表排除重复元素8.打乱一个排好序的列表...【阅读全文】
可怜的猪头 | 2019-03-06 13:45:58 | 阅读(1530) | 评论(0)
那么怎么能够让类只创建一个实例,而后再创建的实例是返回上一次的对象的引用呢?我们了解到,python中,一个类创建对象实例是通过调用父类object的 __new__(cls)方法来创建对象的我们可以通过重写 __new__(cls)方法去实现类只创建一个实例代码如下:    class Earth(object):    ...【阅读全文】
可怜的猪头 | 2019-03-01 13:53:30 | 阅读(14960) | 评论(0)
[root@localhost /]# [root@localhost /]# cat ./for.py #!/bin/pythonfrom random import randintfrom itertools import chaina=[randint(10,100) for _ in range(20)]b=[randint(10,100) for _ in range(20)]c=[randint(10,100) for _ in range(20)]for n,m,v in zip(a,b,c):    print n+m+vcou...【阅读全文】
873313579 | 2019-02-28 22:05:25 | 阅读(1910) | 评论(0)
#!/urs/bin/env pythonimport randomall_choice = ['石头','剪刀','布']win_list = [['石头','剪刀'],['剪刀','布'],['布','石头']]prompt = """(0) 石头(1) 剪刀(2) 布Please input your choice(0/1/2): """computer = random.choice(all_choice)ind = int(input(prompt))player = all_choice[ind]print("Y...【阅读全文】
可怜的猪头 | 2019-02-26 10:53:31 | 阅读(4530) | 评论(0)
[root@localhost /]# [root@localhost /]# cat split.py #!/bin/pythonimport res='aa,bb:cc;dd/tee<ff>gg'def mysplit(s,symbol):    t=[s]    for num in symbol:        res=[]        map(lambda x:res.extend(x....【阅读全文】
可怜的猪头 | 2019-02-25 17:18:32 | 阅读(1880) | 评论(0)
[root@localhost /]# [root@localhost /]# cat strduiqi.py #!/bin/pythonimport os, statli=os.listdir('/software/script/shell')st=[n for n in li if n.endswith(('.sh','.py'))]for nm in st:    os.chmod(nm,os.stat(nm).st_mode | stat.S_IXGRP)[root@localhost /]# [root@localhost /]# ...【阅读全文】
可怜的猪头 | 2019-02-25 16:57:05 | 阅读(2520) | 评论(0)
[root@localhost /]# cat strduiqi.py #!/bin/pythonimport relog=open('/var/log/pacman.log').read()print re.sub('(\d{4})-(\d{2})-(\d{2})',r'\2/\3/\1',log)[root@localhost /]# 捕获组命名[root@localhost /]# cat strduiqi.py #!/bin/pythonimport relog=open('/var/log/pacman.log').read()print re.sub...【阅读全文】
可怜的猪头 | 2019-02-25 16:39:44 | 阅读(8520) | 评论(0)
[root@localhost /]# cat strduiqi.py #!/bin/pythonmydict={'name':'zhuliguo','age':29,'student':'student'}length=max(map(len,mydict.keys()))for n in mydict:    print(n.ljust(length),':',mydict[n])[root@localhost /]# 【阅读全文】
可怜的猪头 | 2019-01-24 13:35:46 | 阅读(18800) | 评论(0)
[root@localhost /]# [root@localhost /]# cat cla.py#!/bin/pythonclass zhu():    def __init__(self,chang,kuan,gao):        self.chang=chang        self.kuan=kuan        self.gao=gao &n...【阅读全文】
可怜的猪头 | 2019-01-24 13:09:48 | 阅读(12460) | 评论(0)
[root@localhost /]# [root@localhost /]# cat zlg.py #!/bin/pythonfrom functools import reducea=[1,2,3,4,5,6,7,8,9]b=[2,3,4,5,6,7,8,9,1]r=map(lambda x,y:x+y,a,b)print list(r)x=3y=4print x if x>y else yp=reduce(lambda x,y:x+y,a)print p[root@localhost /]# [root@localhost /]# ...【阅读全文】