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

基本使用

相关文章
相关标签/搜索