Nov-17-2020, 05:58 AM
os.path.join is preferable.
os.sep
is simply a character. So os.sep.join
is just the normal string join. >>> type(os.sep) <class 'str'> >>> os.sep.join(["foobar", "/foo/baz/", "whatever"]) 'foobar//foo/baz//whatever'
os.path.join
joins them with some more intelligence. If you have multiple separators, it will take it down to one. If you have a component that is an absolute path (starts with a separator), it will ignore the paths before it, etc.>>> os.path.join("foobar", "/foo/baz/", "whatever") '/foo/baz/whatever'