The os.path.abspath() is a built-in Python function that returns a normalized absolute version of the pathname, which means the abspath() function returns the pathname to a path passed as a parameter.
The os.path.abspath() takes a path or file name as a parameter representing a file system path.
The abspath() method returns a normalized version of the pathname path.
To work with path functions, import the os module. Then define a path or filename and pass that to the abspath() function, and it returns the normalized path.
import os path = "Netflix.csv" file_name = os.path.abspath(path) print(file_name)
As you can see from the output, I have passed a filename from my current directory, which is a database, and it returns an absolute path to that directory and then the filename.
To change the current directory in Python, you can use the os.chdir() method.
import os path = "Pro.R" os.chdir("/Users/krunal/Desktop/code/R") file_name = os.path.abspath(path) print(file_name)
The os.path.abspath() function removes things like . and .. from the path giving a full path from the root of the directory tree to the named file (or symlink).
That is it for os.path.abspath() function in Python.