I would utilize the PurePath class within pathlib as follows:
from pathlib import PurePath
path = PurePath('C:/Users/user/Downloads/img.jpg')
parent = path.parents[0]
This yields: PureWindowsPath('C:/Users/users/Downloads')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…