Python how to join cross platform paths

1.3k Views Asked by At

If I have a json directory structure that lists paths in mac format ()i.e. "/0000_test/video.mp4" and I want to join it with c:\\ the mac format, is there a way to do this?

So on windows the path would be returned as c:\\0000_test\video.mp4"

I have tried os.path.join to no avail

1

There are 1 best solutions below

0
On BEST ANSWER

You can use os.path.join and os.path.normpath

>>> os.path.normpath(os.path.join('C:', '/0000_test/video.mp4'))
'C:\\0000_test\\video.mp4'

normpath will take care of normalizing the path in a platform specific manner.