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
data_folder = "source_data/text_files/"
file_to_open = data_folder + "raw_data.txt"
f = open(file_to_open)
print(f.read())
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']