pickle -- Python Serialization Tool

Protocol 协议

  • 协议间不兼容

    • 老版本pickle 不能识别新版本 pickle dump 结果

函数

  • pickle.dumps

    • 参数

      • protocol: int

        • 0 ~ pickle.HIGHEST_PROTOCOL
  • pickle.loads
  • pickle.dump
  • pickle.load

注意 缺陷和陷阱

序列化失败

  • 不能序列化 __main__ 模块中的函数

Path 对象和 in 运算符

判断

  • Path.is_absolute()
  • Path.is_relative_to(*other)
  • Path.is_reserved()
  • Path.match(pattern)

    • 通配符匹配

      • eg: '*.py'
  • 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)