For python3.4+, you can use the Path
class
from pathlib import Path
# rpd is a symbolic link
>>> Path('rdp').is_symlink()
True
>>> Path('README').is_symlink()
False
You have to be careful when using the is_symlink()
method. It will return True
as long as the the named object is a symlink, even if the target of the link is non-existent.
For example (Linux/Unix):
ln -s ../nonexistentfile flnk
Then, in your current directory:
>>> from pathlib import Path
>>> Path('flnk').is_symlink()
True
>>> Path('flnk').exists()
False
The programmer has to decide what they really want. Python3 seems to have renamed a lots of classes. It might be worthwhile to read the manual page for the Path class: https://docs.python.org/3/library/pathlib.html