python使用雜談筆記

一. import as配合try except

try:
    from greenlet import getcurrent as get_ident
except ImportError:
    try:
        from thread import get_ident
    except ImportError:
        from _thread import get_ident

參見flask的源碼。按這種方式,我們在後面統一使用get_ident方法。而實際上這個get_iden方法根本就不是一個實現

 

二.如何在即有python27和python3的環境下,更新pip3到18.0

python3 -m pip install --upgrade pip --force-reinstall

 

三.python3對redis的使用操作

1.redis包安裝 pip3 install redis

2.加載

 

四.對裝飾器的理解

def canshu(id):
    print ("canshu=",id)
    def decorator(f,*args,**kwargs):
        print("decorator=",id)
        def addF(*args,**kwargs):
            print("(add F")
            f(*args,**kwargs)
        return addF
    return decorator

@canshu("1")
def testA(a,b):
    print (a+b)

@canshu("2")
def testB(a,b,c):
    print(a+b+c)
if __name__ == '__main__':
    # app.run()
    testA(1,2)
    testA(1,3)
    print("============================")
    testB(1,2,3)

五.如何便利一個對象又不用單獨一行判空

for rulefactory in rules or ():
    self.add(rulefactory)

六.ubuntu如何安裝python3.6.5https://blog.csdn.net/JiekeXu/article/details/80294523

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章