Python ZipFile 路径分隔符 [英] Python ZipFile path separators

查看:44
本文介绍了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.

代码参考:

这篇关于Python ZipFile 路径分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆