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

anatoly techtonik techtonik at gmail.com
Mon Nov 5 13:41:13 CET 2012


It appears that implementation fails on 'foo/bar/'
--
anatoly t.


On Mon, Nov 5, 2012 at 2:08 PM, anatoly techtonik <techtonik at gmail.com> wrote:
> 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