os.path.abspath() method - Python Last Updated : 21 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The os.path.abspath() method in Python's os module is used to get the full (absolute) path of a file or folder. It's useful when you're working with relative paths but need to know the exact location on your system. If you pass a relative path, it converts it to an absolute one and if the path is already absolute, it returns it unchanged. Example: Python import os a = "myfolder/myfile.txt" # Relative path b = os.path.abspath(a) # Get absolute path print(b) OutputUsing os.path.abspath()Explanation: os.path.abspath() convert a relative file path to an absolute path by combining it with the current working directory, then prints the absolute path.Syntax of os.path.abspath()os.path.abspath(path)Parameter: path is a string representing the relative or absolute path.Returns: A string representing the absolute path.Examples of using os.path.abspath()Example 1: In this example, we are using the os.path.abspath() function to get the absolute path of the current script file. Python import os p = os.path.abspath(__file__) # Get absolute path print(p) OutputUsing os.path.abspath()Explanation: __file__ attribute represents the script's relative path and os.path.abspath() converts it to the full absolute path by combining it with the current working directory.Example 2: In this example, we are using the os.path.abspath() function with "." and ".." to get the absolute paths of the current and parent directories. Python import os print("Current Directory:", os.path.abspath(".")) print("Parent Directory:", os.path.abspath("..")) OutputUsing os.path.abspath()Explanation: ." refers to the current directory, so os.path.abspath(".") gives its full path. ".." refers to the parent directory and os.path.abspath("..") returns its absolute path.Example 3: In this example, we are combining a folder and file name using os.path.join() to create a relative path. Python import os f, n = "data", "report.csv" # Folder and file a = os.path.abspath(os.path.join(f, n)) # Absolute path print(a) OutputUsing os.path.abspath()Explanation: This code combines the folder "data" and file "report.csv" using os.path.join() to form a relative path. Then, os.path.abspath() converts that relative path into an absolute path, which is stored in variable a. Comment More infoAdvertise with us Next Article Python | os.path.basename() method N nikhilaggarwal3 Follow Improve Article Tags : Python Python Programs Python OS-path-module Python directory-program Practice Tags : python Similar Reads OS Path module in Python OS Path module contains some useful functions on pathnames. The path parameters are either strings or bytes. These functions here are used for different purposes such as for merging, normalizing, and retrieving path names in Python. All of these functions accept either only bytes or only string obje 2 min read os.path.abspath() method - Python The os.path.abspath() method in Python's os module is used to get the full (absolute) path of a file or folder. It's useful when you're working with relative paths but need to know the exact location on your system. If you pass a relative path, it converts it to an absolute one and if the path is al 2 min read Python | os.path.basename() 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 4 min read Python | os.path.commonpath() 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 submodule of OS module in Python used for common path name mani 2 min read Python | os.path.commonprefix() 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 submodule of OS module in Python used for common path name mani 2 min read Python | os.path.dirname() 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 os.path.exists() method-Python os.path.exists() method in Python check whether a specified path exists or not. This method can be also used to check whether the given path refers to an open file descriptor or not. Example:Pythonimport os print(os.path.exists('/home/User/Desktop/file.txt')) print(os.path.exists('/home/User/Desktop 2 min read Python | os.path.lexists() 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.expanduser() 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 pathname mani 4 min read 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 Like