On this page
  1. os.chdir
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.chdir

Prev: os.access | Up: os | Next: os.chmod
Rel: os.abort, os.access, os.chmod, os.chown
Ref: docs.python.org — os.chdir
Tags: #public #python3 #stdlib #os


Import

import os
from os import chdir

Signature & Overview

os.chdir(path)

Change the current working directory to the specified path.

Usage

import os
from pathlib import Path
import tempfile

orig = os.getcwd()
with tempfile.TemporaryDirectory() as tmp:
    os.chdir(tmp)
    try:
        assert Path(os.getcwd()).resolve() == Path(tmp).resolve()
    finally:
        os.chdir(orig)

Gotchas

REPL Inspect

from os import chdir
help(chdir)

Linked from

Related notes