Why not os.path.join use os.path.sep or os.sep?

To answer your question as simply as possible, just use posixpath instead of os.path.

So instead of:

from os.path import join
join('foo', 'bar')
# will give you either 'foo/bar' or 'foo\\bar' depending on your OS

Use:

from posixpath import join
join('foo', 'bar')
# will always give you 'foo/bar'

Leave a Comment