I wanted to know what is the pythonic function for this :
I want to remove everything before the wa path.
p = path.split(\'/\')
counter
For Python 3.4+, you should use pathlib.PurePath.relative_to. From the documentation:
>>> p = PurePosixPath('/etc/passwd')
>>> p.relative_to('/')
PurePosixPath('etc/passwd')
>>> p.relative_to('/etc')
PurePosixPath('passwd')
>>> p.relative_to('/usr')
Traceback (most recent call last):
File "", line 1, in
File "pathlib.py", line 694, in relative_to
.format(str(self), str(formatted)))
ValueError: '/etc/passwd' does not start with '/usr'
Also see this StackOverflow question for more answers to your question.