Home > Back-end >  python - symlink to another symlink without following the latter symlink
python - symlink to another symlink without following the latter symlink

Time:08-17

I want to create a symbolic link (A) to another symbolic link (B) which point to an actual file (C) on macOS with python >= 3.10:

A -> B -> C

I tried this:

from pathlib import Path

A = Path('/path/to/src')
B = '/path/to/another/symlink'

A.symlink_to(B)

print(A.resolve()) # prints C, not B

But it didn't work.

How do I do this with python?

CodePudding user response:

Use A.readlink() instead of A.resolve().

  • Related