Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

os.path.join

  • os.path.join
  • join
import os

dirname = 'home'
subdirname = 'foo'
filename = 'work.txt'

path = f"{dirname}\\{subdirname}\\{filename}"
print(path)   # home\foo\work.txt

path = os.path.join(dirname, subdirname, filename)
print(path)

# Linux, OSX: home/foo/work.txt
# Windows:    home\foo\work.txt