import pathlib
# path of the given file
print(pathlib.Path("my_file.txt").parent.absolute())
# current working directory
print(pathlib.Path().absolute())
import module_name
path = os.path.dirname(module_name.__file__)
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()))
import os.path
from pathlib import Path
>>> p = r"C:UsersshaliOneDrivecodesetTheory.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']