I want to extract the parent folder from a raw path string. For string without r prefix, I successfully extracted the file path.
from pathlib import Path
des_dirs = '/path/to/my/file'
Path(des_dirs).parents[0]
Output:
> PosixPath('/path/to/my')
For a raw string, I'm unable to extract the parent folder. What am I missing here? Thanks!
from pathlib import Path
des_dirs = r'C:\Users\pp\Desktop\IMAGE_DATA\resized\masks'
Path(des_dirs).parents[0]
Output:
> PosixPath('.')
A reproducible example here