Split a pathname. Return tuple (head, tail) where tail is everything after the final slash. Either part may be empty.
(p)
| 206 | # The resulting head won't end in '/' unless it is the root. |
| 207 | |
| 208 | def split(p): |
| 209 | """Split a pathname. |
| 210 | |
| 211 | Return tuple (head, tail) where tail is everything after the final slash. |
| 212 | Either part may be empty.""" |
| 213 | p = os.fspath(p) |
| 214 | seps = _get_bothseps(p) |
| 215 | d, p = splitdrive(p) |
| 216 | # set i to index beyond p's last slash |
| 217 | i = len(p) |
| 218 | while i and p[i-1] not in seps: |
| 219 | i -= 1 |
| 220 | head, tail = p[:i], p[i:] # now tail has no slashes |
| 221 | # remove trailing slashes from head, unless it's all slashes |
| 222 | head = head.rstrip(seps) or head |
| 223 | return d + head, tail |
| 224 | |
| 225 | |
| 226 | # Split a path in root and extension. |
no test coverage detected