A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/issues/101000 below:

Add os.path.splitroot() function · Issue #101000 · python/cpython · GitHub

Feature or enhancement

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

  1. The drive part has the same meaning as in splitdrive()
  2. The root part is one of: the empty string, a forward slash, a backward slash (Windows only), or two forward slashes (POSIX only)
  3. The tail part is everything following the root.

Similarly to splitdrive(), a splitroot() function would ensure that drive + 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 exposes root as an attribute, and combines drive + root as an attribute called anchor. The anchor has useful properties, e.g. comparing two paths anchors can tell us whether a relative_to() operation is possible.

Pathlib has its own implementation of splitroot(), but its performance is hamstrung by its need for OS-agnosticism. By moving the implementation into ntpath and posixpath we can take advantage of OS-specific rules to improve pathlib performance.

Previous discussion Linked PRs

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4