from pathlib import Path file_path = Path(__file__).parent from pathlib import Path >>> p = r"C:\Users\shali\OneDrive\code\setTheory.pdf" >>> Path(p).anchor 'C:\\' >>> Path(p).parent WindowsPath('C:/Users/shali/OneDrive/code') >>> Path(p).name 'setTheory.pdf' >>> Path(p).stem 'setTheory' >>> Path(p).suffixes ['.pdf'] >>> str(p) "C:\Users\shali\OneDrive\code\setTheory.pdf"import pathlib # path of the given file print(pathlib.Path("my_file.txt").parent.absolute()) # current working directory print(pathlib.Path().absolute())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()))pip install pathy pip install pathy==0.1.3