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

Oleg Broytman phd at phdru.name
Fri Jul 8 15:35:08 CEST 2011


On Fri, Jul 08, 2011 at 10:18:15AM -0300, Facundo Batista wrote:
> >>> 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.

 Look at a slightly better implementation shutil.destinsrc.
Oleg.
-- 
 Oleg Broytman http://phdru.name/ phd at phdru.name
 Programmers don't die, they just GOSUB without RETURN.


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /