[Python-ideas] os.path.split(path, maxsplit=1)

anatoly techtonik techtonik at gmail.com
Mon Nov 5 12:08:05 CET 2012


Implementation.

pathsplit('asd/asd\\asd\sad')  == '['asd', 'asd', 'asd', 'sad']

def pathsplit(pathstr):
    """split relative path into list"""
    path = list(os.path.split(pathstr))
    while '' not in path[:2]:
        path[:1] = list(os.path.split(path[0]))
    if path[0] == '':
        return path[1:]
    return path[:1] + path[2:]
--
anatoly t.


On Mon, Nov 5, 2012 at 9:48 AM, anatoly techtonik <techtonik at gmail.com> wrote:
> Why?
> Because it is critical when comparing paths and non-trivial.
>
> http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python
> http://stackoverflow.com/questions/3167154/how-to-split-a-dos-path-into-its-components-in-python
> http://www.gossamer-threads.com/lists/python/dev/654410
>
>
> --
> anatoly t.



More information about the Python-ideas mailing list