On this page
os.remove
Prev: os.readlink | Up: os | Next: os.removedirs
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.remove
Tags: #public #python3 #stdlib #os
Import
import os
from os import remove
Signature & Overview
os.remove(path, *, dir_fd=None)
Remove a file (same as unlink()).
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "drop.txt"
p.write_text("x", encoding="utf-8")
os.remove(p)
assert not p.exists()
Gotchas
- Files only (identical to
os.unlink): RaisesIsADirectoryError/PermissionErroron directories (useos.rmdir()orshutil.rmtree()).
REPL Inspect
from os import remove
help(remove)
Linked from
Related notes
- tuts/python3/stdlib_module/os/readlink Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/removedirs 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