[Python-ideas] os.path.isparent and os.path.ischild
Andrew Bennetts
andrew at bemusement.org
Fri Jul 8 10:40:24 CEST 2011
Steven D'Aprano wrote:
> 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
Those one-liners are simple, obvious, and dangerously wrong:
>>> ischild('aa', 'a')
True
-Andrew.
More information about the Python-ideas
mailing list