On this page
os.unlink
Prev: os.uname_result | Up: os | Next: os.urandom
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.unlink
Tags: #public #python3 #stdlib #os
Import
import os
from os import unlink
Signature & Overview
os.unlink(path, *, dir_fd=None)
Remove a file (same as remove()).
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "temp.txt"
p.write_text("x", encoding="utf-8")
os.unlink(p)
assert not p.exists()
Gotchas
- Identical to
os.remove(): RaisesFileNotFoundErrorif missing (usePath.unlink(missing_ok=True)to ignore missing files).
REPL Inspect
from os import unlink
help(unlink)
Linked from
Related notes
- tuts/python3/stdlib_module/os/uname_result Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/urandom 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