On this page
  1. os.readlink
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.readlink

Prev: os.read | Up: os | Next: os.remove
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.readlink
Tags: #public #python3 #stdlib #os


Import

import os
from os import readlink

Signature & Overview

os.readlink(path, *, dir_fd=None)

Return a string representing the path to which the symbolic link points.

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    target = Path(tmp) / "real.txt"
    target.write_text("ok", encoding="utf-8")
    link = Path(tmp) / "alias.txt"
    link.symlink_to(target)
    assert Path(os.readlink(link)) == target

Gotchas

REPL Inspect

from os import readlink
help(readlink)

Linked from

Related notes