This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Have a split corresponding with os.path.join
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Add os.path.splitpath(path) function
View: 11344
Assigned To: Nosy List: amaury.forgeotdarc, martin.panter, nidoizo, nnorwitz, orsenthil, r.david.murray, rhettinger
Priority: low Keywords: easy, patch

Created on 2004-02-11 16:36 by nidoizo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
splitall.py nidoizo, 2004-05-26 13:30
Messages (12)
msg45375 - (view) Author: Nicolas Fleury (nidoizo) Date: 2004-02-11 16:36
I would be nice to have a function to do the exact
opposite of os.path.join, something like an
os.path.splitall or fullsplit.

Rationale:
Currently, on Windows, using os.path.split produce the
following result:
 os.path.split('Z:/xyz') => ('Z:/', 'xyz')
It exceptionaly keep the \ after the drive.  This
exception makes str.split incompatible with
os.path.join that is expecting the \.

Spliting fully a path is useful when transforming
absolute paths to relative paths.  I could also be nice
to have a function to do that in os.path.
msg45376 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-05-21 06:17
Logged In: YES 
user_id=80475

Do you have a patch in mind?
msg45377 - (view) Author: Nicolas Fleury (nidoizo) Date: 2004-05-25 13:12
Logged In: YES 
user_id=151545

I have attached a possible implementation (not tested on
Unix).  Feel free to ask if I can do more.
msg45378 - (view) Author: Nicolas Fleury (nidoizo) Date: 2004-05-25 13:13
Logged In: YES 
user_id=151545

I have attached a possible implementation (not tested on
Unix).  Feel free to ask if I can do more.
msg45379 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-16 06:01
This is close enough to a patch so moving.  As a patch, this has more chance of being resolved one way or the other.
msg90063 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-07-03 15:24
I still fail to see how 'splitall' would be useful.
How is it a problem that "str.split is incompatible with os.path.join" ?
msg90069 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-07-03 18:00
I think the OP meant os.path.split, not str.split, but I don't
understand what incompatibility he is referring to.  This seems to work
fine:

>>> ntpath.join(*ntpath.split("Z:/xyz"))
'Z:/xyz'

That said, I'd like to note that I was surprised the first few times I
used os.path.split to find that it did only one split.  I fully expected
it to be symetric with os.path.join and analogous to str.split and give
me a list of path components.

After thinking about this for a while, I think there are enough
subleties involved in doing this operation that it would be worth having
a cannonical function to do it the "right way" (which, IMO, is not how
the proposed patch does it!)

Here is what I think it should produce:

  D:/abc\\xyz.ext   -->    ['D:\\', 'abc', 'xyz.ext']
  D:abc/xyz.ext     -->    ['D:', 'abc', 'xyz.ext']
  
I don't think this is what the OP is expecting, but I think it is
necessary to keep the drive attached to the first path element to avoid
ambiguity and to be consistent with the rest of the os.path semantics.

The reason I think this is worth doing is that otherwise what one would
do to produce the list of path components would be something like:

  drive, rpath = splitdrive(normpath("D:/abc/def.ext"))
  pathcomponents = rpath.split(sep)

which produces the result:

   ['', 'abc', 'def.ext']

when what one really wants is:

   ['\\', 'abc', 'def.ext']

Yes, your code can treat '' as indicating an absolute path, but that
adds one more step to the mutlistep process, the omission of any one of
which leads to subtle bugs.  Better to have a function that does it right.

Now, the question is, are there enough real use cases for this function
to motivate someone to do the work to add it?  I don't have any myself.
msg114320 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-19 05:45
I'll close this in a couple of weeks as won't fix unless anyone objects.
msg114324 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-08-19 05:56
Mark, +1 objection against closing this.
msg114355 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-19 12:28
It is, however, clearly languishing for want of an implementer...
msg210893 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-02-11 00:43
I suggest closing this in favour of issue 11344, “Add os.path.splitpath(path) function”, which has a more complete patch ready.
msg210895 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-11 01:42
I agree that that is a superseder, although it sounds like it may not be needed since pathlib is part of 3.4 (albeit provisional).
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39926
2014-02-11 01:42:14r.david.murraysetstatus: languishing -> closed
superseder: Add os.path.splitpath(path) function
messages: + msg210895

resolution: duplicate
stage: test needed -> resolved
2014-02-11 00:43:03martin.pantersetnosy: + martin.panter
messages: + msg210893
2014-02-03 19:55:05BreamoreBoysetnosy: - BreamoreBoy
2010-08-19 12:28:24r.david.murraysetstatus: open -> languishing

messages: + msg114355
2010-08-19 05:56:25orsenthilsetstatus: pending -> open
nosy: + orsenthil
messages: + msg114324

2010-08-19 05:45:57BreamoreBoysetstatus: open -> pending
versions: - Python 2.7
nosy: + BreamoreBoy

messages: + msg114320
2009-07-03 18:00:05r.david.murraysetpriority: normal -> low
versions: + Python 3.2
nosy: + r.david.murray

messages: + msg90069
2009-07-03 15:24:23amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg90063
2009-04-22 17:17:58ajaksu2setkeywords: + easy
2009-02-14 11:31:52ajaksu2setstage: test needed
type: enhancement
components: + Library (Lib), - None
versions: + Python 2.7
2004-02-11 16:36:28nidoizocreate