pathlib

Table of Contents

Overview

from pathlib import Path

p = Path('/path/to/file')
print(p.parents[0])  # /path/to
print(p.parents[1])  # /path

p.mkdir(parents=True, exist_ok=True)