What is the difference between os.path.basename() and os.path.dirname()?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both functions use the
os.path.split(path)
function to split the pathnamepath
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'