waldelb
waldelb

Reputation: 765

How to create a relative symbolic link to a non-existing file in python

ln -s foo /some/path/to/bar

doesn't ask whether foo exists and just creates a relative symbolic link "bar" that points to a nonexistent foo.

What is the python equivalent of this?

Upvotes: 1

Views: 856

Answers (1)

MassPikeMike
MassPikeMike

Reputation: 682

You can do:

import os

os.symlink("foo", "/some/path/to/bar")

Because the first argument is not an absolute path, this will create a link /some/path/to/bar pointing to the (possibly nonexistent) /some/path/to/foo.

Upvotes: 3

Related Questions