我在 Windows 上使用 Paramiko 访问远程 SFTP 服务器。我需要对远程路径做一些工作,例如 os.path.join
、os.path.commonprefix
等。由于我的主机平台是 Windows,因此所有路径操作都带有\
分隔符,但我需要 POSIX 样式的路径。
有没有办法在Windows上使用Python内置的POSIX路径操作?
最佳答案
正如 documentation 中指出的那样(第二注)
... you can also import and use the individual modules if you want to manipulate a path that is always in one of the different formats. They all have the same interface:
posixpath
for UNIX-style pathsntpath
for Windows paths
因此您可以导入 posixpath
并将其用作 os.path
>>> import posixpath
>>> posixpath.join
<function join at 0x025C4170>
>>> posixpath.join('a','b')
'a/b'
>>> posixpath.commonprefix
<function commonprefix at 0x00578030>
关于python - 在 Windows 上使用 os.path 进行 POSIX 路径操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36592213/