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

I am new to Python programming, and during the study I had this doubt about these two functions. I already searched for answers and read some links, but did not understand. Can someone give some simple explanation?

+50
python
Mar 08 '14 at 16:35
source share
1 answer

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

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

For example: dirname '/foo/bar/item' - '/foo/bar' .

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

For example: Base name '/foo/bar/item' returns 'item'

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

+105
Mar 08 '14 at 16:35
source share



All Articles