[Python-ideas] os.path.isparent and os.path.ischild
Steven D'Aprano
steve at pearwood.info
Fri Jul 8 10:00:26 CEST 2011
Giampaolo RodolĂ wrote:
>>>> isparent('/a', '/a/b')
> True
I'm not sure that this is so common and useful that it needs to be
included in os.path. You can always just add it to your own library, or
even write them in-line: the implementation is just a one-liner.
def isparent(path1, path2):
"Returns True if path1 is a parent of path2."
return os.path.commonprefix([path1, path2]) == path1
def ischild(path1, path2):
"Returns True if path1 is a child of path2."
return os.path.commonprefix([path1, path2]) == path2
--
Steven
More information about the Python-ideas
mailing list