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

Current directory (getcwd, pwd, chdir)

  • getcwd
  • pwd
  • chdir
import sys
import os

to_dir = '..'
# to_dir = '/path/to/some/dir'
if len(sys.argv) == 2:
    to_dir = sys.argv[1]

current_dir = os.getcwd()
print(current_dir)

os.chdir(to_dir)

new_dir = os.getcwd()
print(new_dir)

Linux, OSX:

$ pwd

Windows: (cd without parameters prints the current working directory)

> cd