liveBook · Manning

Os.path.split

As explained in The Quick Python Book, Fourth Edition

os.path.split is a Python function that separates a pathname into its directory portion and final path component.

os.path.split separates a pathname into a two-element tuple: the directory portion and the final path component, or basename. section 12.2.4

Split a pathname

import os os.path.split(os.path.join('some', 'directory', 'path')) # ('some/directory', 'path')

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains the two-element tuple through a runnable example, without descending into implementation details or extensive edge cases.
Examples
Demonstrates splitting a path assembled with os.path.join and contrasts the result with basename and dirname outputs.
What you can do after
Apply it to retrieve a pathname’s parent portion and final component as a tuple.
How it connects
Connects os.path.split with os.path.basename, os.path.dirname, os.path.splitext, and os.path.join.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.