joblib ---- a Python Parallel and Function Disk Cache Tool
用途
加速函数执行
- 函数结果缓存
- 第二次执行,直接返回缓存的结构,无需执行代码块
- 并行运算
替代 pickle
- 更高效
- 函数式编程
Memory 类
- 作用缓存 函数 执行结果
- 参考:On demand recomputing: the Memory class
- 支持对 numpy 的优化
pickle -- Python Serialization Tool
教程
Protocol 协议
协议间不兼容
- 老版本pickle 不能识别新版本 pickle dump 结果
函数
pickle.dumps
参数
protocol: int
- 0 ~ pickle.HIGHEST_PROTOCOL
- pickle.loads
- pickle.dump
- pickle.load
注意 缺陷和陷阱
Path 对象和 in 运算符
判断
- Path.is_absolute()
- Path.is_relative_to(*other)
- Path.is_reserved()
Path.match(pattern)
通配符匹配
- eg:
'*.py'
- eg:
- Path.exists()
- Path.samefile(other: Path)
- Path.is_dir()
- Path.is_file()
- Path.is_symlink()
- Path.is_mount()
- Path.is_socket()
- Path.is_fifo()
- Path.is_block_device()
- Path.is_char_device()
修改组分(返回新 Path)
Path.with_name(name)
- 替换 basename
Path.with_stem(stem)
- 替换 stem (除去 suffix 部分)
Path.with_suffix(suffix)
shutil ---- Python File Operating Module
命令
which
- shutil.which
移动
- shutil.move
复制
shutil.copy
- 复制 内容 + mode
shutil.copy2
- 复制 content + all_metadata
shutil.copystat(src, target)
- 复制 stat, 不是内容
注意:
- 复制到的对象,target 必须存在
- 可能不完全一致
shutil.copyfileobj(fsrc, fdst[, length])
psutil -- Python vmstat like tool
cpu_count
代码
1 2 3import psutil psutil.cpu_count(logical=False)- 统计 CPU 核心数量
- logical : 是否统计 单核多线程