Returns the directory component of a pathname
(p)
| 174 | # Return the head (dirname) part of a path, same as split(path)[0]. |
| 175 | |
| 176 | def dirname(p): |
| 177 | """Returns the directory component of a pathname""" |
| 178 | p = os.fspath(p) |
| 179 | sep = _get_sep(p) |
| 180 | i = p.rfind(sep) + 1 |
| 181 | head = p[:i] |
| 182 | if head and head != sep*len(head): |
| 183 | head = head.rstrip(sep) |
| 184 | return head |
| 185 | |
| 186 | |
| 187 | # Is a path a mount point? |