28 Sep
2015
28 Sep
'15
11:58 a.m.
On 28 September 2015 at 12:46, Todd
I think it would be useful if "os.path.split" also had a "maxsplit" option. This would default to "1" (the current behavior"), but could be set to any value allowed by "str.split". Using this option would follow the behavior of "str.rsplit" for that value of "maxsplit".
In Python 3.6+ (which is the only place a change like this is likely to happen) you're probably better using pathlib. There, you can use path.parts, which returns a tuple of the path elements, so you can do things like >>> Path('C:\\what\\ever\\you\\like.txt').parts[-3:] ('ever', 'you', 'like.txt') That's usable now in Python 3.4+, and a backport is available at https://pypi.python.org/pypi/pathlib/ Paul