What is the difference between os.path.basename() and os.path.dirname()?

后端 未结 2 1913
遥遥无期
遥遥无期 2021-01-29 18:49

What is the difference between os.path.basename() and os.path.dirname()?

I already searched for answers and read some links, but didn\'t unde

2条回答
  •  别那么骄傲
    2021-01-29 19:21

    Both functions use the os.path.split(path) function to split the pathname path into a pair; (head, tail).

    The os.path.dirname(path) function returns the head of the path.

    E.g.: The dirname of '/foo/bar/item' is '/foo/bar'.

    The os.path.basename(path) function returns the tail of the path.

    E.g.: The basename of '/foo/bar/item' returns 'item'

    From: http://docs.python.org/2/library/os.path.html#os.path.basename

提交回复
热议问题