Split a pathname. Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.
(p, /)
| 99 | # Trailing '/'es are stripped from head unless it is the root. |
| 100 | |
| 101 | def split(p, /): |
| 102 | """Split a pathname. Returns tuple "(head, tail)" where "tail" is |
| 103 | everything after the final slash. Either part may be empty.""" |
| 104 | p = os.fspath(p) |
| 105 | sep = _get_sep(p) |
| 106 | i = p.rfind(sep) + 1 |
| 107 | head, tail = p[:i], p[i:] |
| 108 | if head and head != sep*len(head): |
| 109 | head = head.rstrip(sep) |
| 110 | return head, tail |
| 111 | |
| 112 | |
| 113 | # Split a path in root and extension. |