On this page
os.mkdir
Prev: os.makedirs | Up: os | Next: os.open
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.mkdir
Tags: #public #python3 #stdlib #os
Import
import os
from os import mkdir
Signature & Overview
os.mkdir(path, mode=511, *, dir_fd=None)
Create a directory.
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
sub = Path(tmp) / "single"
os.mkdir(sub)
assert sub.is_dir()
Gotchas
- Creates one level only: Raises
FileNotFoundErrorif parent directories don't exist andFileExistsErrorif it already exists—useos.makedirs(..., exist_ok=True)for nested paths.
REPL Inspect
from os import mkdir
help(mkdir)
Linked from
Related notes
- tuts/python3/stdlib_module/os/makedirs Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/open Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib