Get the Full Path of the Current Working Directory
In this example, you will learn to get the full path of the current working directory.
To understand this example, you should have the knowledge of the following topics:
Example 1: Using pathlib module
import pathlib
// path of the given file
print(pathlib.Path("my_file.txt").parent.absolute())
// current working directory
print(pathlib.Path().absolute())
Output
/Users/username
/Users/username
Example 2: Using os module
import os
// path of the given file
print(os.path.dirname(os.path.abspath("my_file.txt")))
// current working directory
print(os.path.abspath(os.getcwd()))