Python ZipFile 路径分隔符

Python ZipFile 路径分隔符

问题描述:

如果我使用 Python ZipFile 库解压一个 Zip 文件,该文件是在 Windows 上创建的,但我的代码在类 Unix 上运行,路径分隔符是否始终是 Unix 风格的?

If I am unzipping a Zip file with the Python ZipFile library, where the file was created on Windows, but my code is running on Unix-like, will the path separators always be Unix-style?

在内部,ZipFile 按照 zip 文件规范.

Internally, ZipFile stores forward slashes as required by the zip file specification.

在外部,它们使用 os.sep 进行翻译,因此它将匹配通常预期在给定平台上.

Externally, they get translated using os.sep so it will match what is normally expected on a given platform.

代码参考: