Skip to content

Instantly share code, notes, and snippets.

@miyakogi
Created January 17, 2015 13:56
Show Gist options
  • Save miyakogi/90a99a11aac0515c99fd to your computer and use it in GitHub Desktop.
Save miyakogi/90a99a11aac0515c99fd to your computer and use it in GitHub Desktop.
pathlib.Path.relative_to
from os import path
print(path.relpath('/a/b', '/a')) # >>> b
print(path.relpath('/a', '/a/b')) # >>> ..
from pathlib import Path
a = Path('/a')
b = Path('/a/b')
print(b.relative_to(a)) # >>> b
print(a.relative_to(b)) # ValueError!!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment