>>> p = os.path.join(os.getcwd(), 'foo.txt')
>>> p
'/Users/csaftoiu/tmp/foo.txt'
>>> os.path.dirname(p)
'/Users/csaftoiu/tmp'
>>> os.path.basename(p)
'foo.txt'
>>> os.path.split(os.getcwd())
('/Users/csaftoiu/tmp', 'foo.txt')
>>> os.path.splitext(os.path.basename(p))
('foo', '.txt')
# The correct operator to extend a pathlib object is /
from pathlib import Path
dir_path = Path('directory')
subdir_path = dir_path / "subdir_path"
1
2
>>> os.path.join("foobar", "/foo/baz/", "whatever")
'/foo/baz/whatever'
1
2
3
4
>>> type(os.sep)
<class 'str'>
>>> os.sep.join(["foobar", "/foo/baz/", "whatever"])
'foobar//foo/baz//whatever'