Use pathlib module to perform your task, for ref. check the syntax below:
from inspect import currentframe, getframeinfo
from pathlib import Path
filename = getframeinfo(currentframe()).filename
parent = Path(filename).resolve().parent
I am using this from Python 3.4 and it also works in all versions above that, but I am not sure about the older ones.
Happy Learning