Skip to content

Instantly share code, notes, and snippets.

@NoahCardoza
Created September 21, 2020 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahCardoza/bce83cd899175e9dfa90b13744c06454 to your computer and use it in GitHub Desktop.
Save NoahCardoza/bce83cd899175e9dfa90b13744c06454 to your computer and use it in GitHub Desktop.
Python: split_path
# Author: noahcardoza@gmail.com
from os import path
def split_path(location):
"""splits the path into a tuple of all it's parts using recursion"""
head, tail = path.split(location)
if tail:
return split_path(head) + (tail,)
if head:
return (head,)
return tuple()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment