[Python-ideas] os.path.isparent and os.path.ischild

Facundo Batista facundobatista at gmail.com
Fri Jul 8 15:18:15 CEST 2011


On Thu, Jul 7, 2011 at 8:08 PM, Giampaolo Rodolà <g.rodola at gmail.com> wrote:

>>>> isparent('/a', '/a/b')
> True
>>>> isparent('/a/b', '/a')
> False
>
>>>> ischild('/a/b', '/a')
> True
>>>> ischild('/a', '/a/b')
> False


>>> def isparent(a, b):
...   a += os.path.sep
...   return b.startswith(a)
...
>>> isparent('/a', '/a/b')
True
>>> isparent('/a/b', '/a')
False
>>> isparent('/ab/c', '/a')
False


See the append of the path separator for the third case later.

ischild() would be very similar.

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/



More information about the Python-ideas mailing list