We now have a youtube channel. Subscribe!

Python os.readlink() Method with example

Hello dear readers! Welcome back to another section of our tutorial on Python. In this tutorial guide, we are going to be studying about the Os readlink() method.

The Python os readlink() method returns a string that represents the path to which the symbolic link points. It may return an absolute or a relative pathname.


The following below is the syntax for Python Os readlink() method -

os.readlink( path )

Parameter Details

  • path - It is the path for which we are going to find source of the link.

Return Value

This returns a string representing the path to which the symbolic link point to.


The following below is a simple example -

# !/usr/bin/python
import os

src = '/usr/bin/python'
dst = '/tmp/python'

# This creates a symbolic link on python in tmp directory
os.symlink(src, dst)

# Now let us use readlink to display the source of the link.
path = os.readlink( dst )
print path

Let us compile and run the above program, this creates a symbolic link to usr/ben/python and later it will then read the source of the symbolic link using readlink() call. Before you run this program, make sure you do not have /tmp/Python already available.


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python OS remove() Method.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain