I'm using Paramiko on Windows to access a remote SFTP server. I need to do some work with remote paths like os.path.join
, os.path.commonprefix
, etc. Since my host platform is Windows, all paths operations come with the \
separator, but I need POSIX-styled paths.
Is there any way to use Python built-in POSIX path operations on Windows?
As pointed out in the documentation (2nd note)
... 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
So you could import posixpath
and use it as os.path
>>> import posixpath
>>> posixpath.join
<function join at 0x025C4170>
>>> posixpath.join('a','b')
'a/b'
>>> posixpath.commonprefix
<function commonprefix at 0x00578030>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With