Section: Files and paths

Use pathlib

python
python
from pathlib import Path
path = Path("src") / "main.py"
exists = path.exists()

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Files and paths
Read a text file
Read a text file
OpenIn sheetpythonsame section
Read line by line
Read line by line
OpenIn sheetpythonsame section
Write a text file
Write a text file
OpenIn sheetpythonsame section
Append to a file
Append to a file
OpenIn sheetpythonsame section
Read JSON from disk
Read JSON from disk
OpenIn sheetpythonsame section
f-string interpolation
f-string interpolation