Delete Files

Use the os or pathlib modules to delete files and check paths.

Example
import os
from pathlib import Path

path = "temp.txt"
Path(path).write_text("temporary", encoding="utf-8")

if os.path.exists(path):
    os.remove(path)
    print("Deleted")
else:
    print("File not found")

# pathlib style
p = Path("another.txt")
p.write_text("x", encoding="utf-8")
p.unlink(missing_ok=True)