Python | os.path.realpath() method Last Updated : 18 Jun, 2019 Comments Improve Suggest changes Like Article Like Report OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation. os.path.realpath() method in Python is used to get the canonical path of the specified filename by eliminating any symbolic links encountered in the path. Syntax: os.path.realpath(path) Parameter: path: A path-like object representing the file system path. A path-like object is either a string or bytes object representing a path. Return Type: This method returns a string value which represents the canonical path. Create a soft link or symbolic link In Unix or Linux, soft link or symbolic link can be created using ln command. Below is the syntax to create a symbolic link at the shell prompt: $ ln -s {source-filename} {symbolic-filename} Example: Example: In above output, "/home/ihritik/Desktop/file(shortcut).txt" is a symbolic link. Code : Use of os.path.realpath() method to get canonical path and resolve symbolic links Python3 # Python program to explain os.path.realpath() method # importing os module import os # Path path = "/home / ihritik / Desktop / file(shortcut).txt" # Get the canonical path # of the specified path # by eliminating any symbolic links # encountered in the path real_path = os.path.realpath(path) # Print the canonical path print(real_path) # Path path = "/../../GeeksForGeeks / sample.py" # Get the canonical path # of the specified path # eliminating any symbolic links # encountered in the path real_path = os.path.realpath(path) # Print the canonical path print(real_path) # Path path = "file.txt" # Get the canonical path # of the specified path # eliminating any symbolic links # encountered in the path real_path = os.path.realpath(path) # Print the canonical path print(real_path) os.chdir("/home / ihritik / Downloads/") # Path path = "file.txt" # Get the canonical path # of the specified path # eliminating any symbolic links # encountered in the path real_path = os.path.realpath(path) # Print the canonical path print(real_path) Output: /home/ihritik/Documents/file(original).txt /GeeksForGeeks/sample.py /home/ihritik/file.txt /home/ihritik/Downloads/file.txt Reference: https://docs.python.org/3/library/os.path.html Comment More infoAdvertise with us Next Article Python | os.path.realpath() method I ihritik Follow Improve Article Tags : Python python-os-module Python OS-path-module Practice Tags : python Similar Reads Python | os.path.expandvars() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path the module is a submodule of OS module in Python used for common pathname 3 min read Python | os.path.getatime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getmtime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.getctime() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.size() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system-dependentthe functionality. os.path module is a submodule of the OS module in Python used for common path 2 min read Python | os.path.isabs() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python os.path.isfile() method The os.path.isfile() method in Python is used to check if a path refers to a regular file (not a directory or any other type of file system object). This method can be particularly useful when you need to validate file paths before performing file operations like reading, writing, or modifying files 2 min read os.path.isdir() method - Python os.path.isdir() method in Python checks whether the specified path is a directory or not. This method follows the symbolic link, which means if the specified path is a symbolic link pointing to an existing directory then the method will return True.Example: Using os.path.isdir() methodThis code demo 2 min read Python | os.path.islink() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name man 2 min read Python | os.path.ismount() method os.path module is sub module of Python OS Module in Python used for common path name manipulation. os.path.ismount() method in Python is used to check whether the given path is a mount point or not. A mount point is a point in a file system where a different file system has been mounted. os.path.ism 2 min read Like