Search code examples
pythonpython-3.xpython-3.7

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?


Solution

  • 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.