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

Ben Finney ben+python at benfinney.id.au
Thu Jul 14 03:14:04 CEST 2011


Paul Colomiets <paul at colomiets.name> writes:

> Hi,
>
> On Fri, Jul 8, 2011 at 2:08 AM, Giampaolo Rodolà <g.rodola at gmail.com> wrote:
> >>>> isparent('/a', '/a/b')
> > True
> >>>> ischild('/a/b', '/a')
> > True
>
> Do you mean:
>
> >>> '/a' == dirname('/a/b')
> True
> >>> dirname('/a/b') == '/a'
> True
>
> I do not think it's harder to write.

I think this behaviour is also part of the expectation::

    >>> path = '/a/b/c/d'

    >>> isparent('/a', path)
    True
    >>> isparent('/a/b', path)
    True
    >>> isparent('/a/b/z', path)
    False

    >>> ischild(path, '/a')
    True
    >>> ischild(path, '/a/b')
    True
    >>> ischild(path, '/a/b/z')
    False

    >>> '/a' == dirname(path)
    False
    >>> '/a/b' == dirname(path)
    False
    >>> '/a/b/z' == dirname(path)
    False

-- 
 \       “See, in my line of work you gotta keep repeating things over |
  `\       and over and over again, for the truth to sink in; to kinda |
_o__)               catapult the propaganda.” —George W. Bush, 2005-05 |
Ben Finney




More information about the Python-ideas mailing list