| name | python-pathlib |
| description | Python pathlib usage guidelines for file and directory operations |
| license | MIT |
| compatibility | opencode |
| metadata | {"related_python_guidelines":"For general Python development standards, use skill `python-guidelines`","related_python_naming":"For _file and _dir naming conventions, use skill `python-naming`"} |
Python Pathlib
What I Do
Provide guidelines for using Python's pathlib module for all file system paths.
Path Rules
Always Use Pathlib
from pathlib import Path
config_path = Path("config/settings.json")
data_dir = Path("data/output")
file_path = data_dir / "results.csv"
config_path = "config/settings.json"
data_dir = "data/output"
import os.path
path = os.path.join("data", "output")
Path Operations
from pathlib import Path
base = Path("data")
output_file = base / "results.csv"
subdir_file = base / "processed" / "output.json"
path.is_file()
path.is_dir()
path.exists()
path.read_text()
path.read_bytes()
path.write_text(content)
path.write_bytes(data)
path.mkdir(parents=True, exist_ok=True)
path.iterdir()
path.rglob("*.py")
Context Managers
from pathlib import Path
input_file = Path("input.txt")
with input_file.open("r") as f:
data = f.read()
content = Path("config.json").read_text()
When to Use Me
Use this skill when:
- Handling file paths
- Managing directory operations
- Reading or writing files
- Any Path-related work
Key Rules
- Never use strings for paths - Always use Path objects
- Never use os.path - Use pathlib instead
- Use / operator - For path concatenation
- Use with statements - For file I/O
- Type annotate as Path -
path: Path