python3學習筆記

簡介

python寫的程序多了,發現不少方法,不少小工具能夠複用,記錄起來,作成目錄,或者直接貼代碼python

1、python內置

單例模式

class Singleton:
    """單例"""

    _instance_lock = Lock()  # 新建實例用到的鎖

    def __init__(self, hub_url):
        pass

    def __new__(cls, *args, **kwargs):
        if not hasattr(Singleton, "_instance"):
            with Singleton._instance_lock:
                if not hasattr(Singleton, "_instance"):
                    Singleton._instance = object.__new__(cls)
                    Singleton._instance.hub_url = args[0]  # 屬性賦值什麼的,好像只能放在這
        return Singleton._instance

Logging日誌模塊

Loggingmysql

裝飾器

計時裝飾器git

def timer(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        start = time.time()
        print('開始時間: {}'.format(start))
        result = func(*args, **kwargs)
        ended = time.time()
        print('結束時間: {}, 耗時: {}'.format(ended, ended-start))
        return result
    return wrapper

多線程

上下文管理器

2、數據庫

redis

mysql

增刪查改(待更)redis

3、爬蟲相關

requests

(待更)sql

scrapy

aiohttp

pyquery

解析庫,(待更)docker

selenium

4、git相關

.gitignore

5、docker

基本使用

相關文章
相關標籤/搜索