[Python-ideas] os.path.split(path, maxsplit=1)
techtonik at gmail.com
Wed Nov 7 07:23:49 CET 2012
On Tue, Nov 6, 2012 at 1:22 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 05/11/12 23:52, Ned Batchelder wrote:
>> Anatoly, I appreciate the energy and dedication you've shown to the
>> Python community, but maybe you should spend a little more time on
>> each proposal? For example, the subject line here is a different (and
>> already taken) function name than the implementation, and has a
>> maxsplit argument that the implementation doesn't have.
It's the idea to add maxsplit argument to os.path.split(). If the idea
is good, it will be developed into actual proposal.
I've included prototype code, because in the past people complained
about the absence of source code. The name in prototype function is
different, because it uses os.path.split internally, which clashes.
Here is the working prototype. Attached is with test case from SO.
Note that it behaves differently on Windows, Python 3 because of the
def pathsplit(pathstr, maxsplit=):
"""split relative path into list"""
path = [pathstr]
oldpath = path[:]
path[:1] = list(os.path.split(path))
if path == '':
path = path[1:]
elif path == '':
path = path[:1] + path[2:]
if path == oldpath:
if maxsplit is not None and len(path) > maxsplit:
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1144 bytes
Desc: not available
More information about the Python-ideas