Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add os.path.splitroot() function #101000

Closed
Closed
Labels
3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement
@barneygale

Description

@barneygale

Feature or enhancement

Add a function that splits a path into a(drive, root, tail) triad:

  1. Thedrive part has the same meaning as insplitdrive()
  2. Theroot part is one of: the empty string, a forward slash, a backward slash (Windows only), or two forward slashes (POSIX only)
  3. Thetail part is everything following the root.

Similarly tosplitdrive(), asplitroot() function would ensure thatdrive + root + tail is the same as the input path.

Pitch

The extra level of detail reflects an extra step in the Windows 'current path' hierarchy -- Windows has both a 'current drive', and a 'current directory' for one or more drives, which results in several kinds of non-absolute paths, e.g. 'foo/bar', '/foo/bar', 'X:foo/bar'

This three-part model is used successfully by pathlib, which exposesroot as an attribute, and combinesdrive + root as an attribute calledanchor. The anchor has useful properties, e.g. comparing two paths anchors can tell us whether arelative_to() operation is possible.

Pathlib hasits own implementation ofsplitroot(), but its performance is hamstrung by its need for OS-agnosticism. By moving the implementation intontpath andposixpath we can take advantage of OS-specific rules to improve pathlib performance.

Previous discussion

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp