def path_retreat(thepath, sep=os.sep):
'''generator to iterate over a file path in reverse
:param str thepath: the path to retreat over
:param str sep: *Default: os.sep* - the path separator to use
:returns: (iter)able of strings
'''
pre = ''
if thepath[0] == sep:
pre = sep
parts = thepath.split(sep)
while parts:
if os.path.join(*parts):
yield '%s%s' % (pre, os.path.join(*parts))
parts = parts[:-1]
评论列表
文章目录