I want to do some path resolution in python without assuming file separator char. In JS you use path.resolve(__dirname, '..','xxx','yyy') to get $PWD/../xxx/yyy on *nix machines. Is there an equivalent function in python?
As James Smith pointed out, you can use os.path.join function.
import os
os.path.join(os.getcwd(), '..', 'xxx', 'yyy') # Returns $PWD/../xxx/yyy
It joins one or more path components using the platform specific directory separator. Could be used for both relative and absolute paths.
os.path.join('foo', 'bar') # Returns foo/bar
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