On this page
os.symlink
Prev: os.statvfs_result | Up: os | Next: os.system
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.symlink
Tags: #public #python3 #stdlib #os
Import
import os
from os import symlink
Signature & Overview
os.symlink(src, dst, target_is_directory=False, *, dir_fd=None)
Create a symbolic link pointing to src named dst.
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp) / "target.txt"
src.write_text("ok", encoding="utf-8")
dst = Path(tmp) / "link.txt"
os.symlink(src, dst)
assert dst.is_symlink() and dst.read_text(encoding="utf-8") == "ok"
Gotchas
- Argument order is
(target, link_name): Easy to reverse by accident—Path.symlink_to(target)reads more naturally (link.symlink_to(target)). - Windows requires Developer Mode or admin privileges to create symlinks.
REPL Inspect
from os import symlink
help(symlink)
Linked from
Related notes
- tuts/python3/stdlib_module/os/statvfs_result Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/system 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