I'm new in Python programming and while studying I had this doubt about this two functions. I already searched for answers and read some links, but didn't understood. Can anyone give some simple explanation?
我是Python编程的新手,在学习的过程中,我对这两个函数产生了疑问。我已经搜索了答案并阅读了一些链接,但没有理解。谁能给出一些简单的解释?
1 个解决方案
#1
144
Both functions use the os.path.split(path)
function to split the pathname path
into a pair; (head, tail)
.
这两个函数都使用os.path.split(path)函数将路径名路径拆分为一对; (头,尾)。
The os.path.dirname(path)
function returns the head of the path.
os.path.dirname(path)函数返回路径的头部。
E.g.: The dirname of '/foo/bar/item'
is '/foo/bar'
.
例如:'/ foo / bar / item'的目录是'/ foo / bar'。
The os.path.basename(path)
function returns the tail of the path.
os.path.basename(path)函数返回路径的尾部。
E.g.: The basename of '/foo/bar/item'
returns 'item'
例如:'/ foo / bar / item'的基本名称返回'item'
From: http://docs.python.org/2/library/os.path.html#os.path.basename
来自:http://docs.python.org/2/library/os.path.html#os.path.basename
#1
144
Both functions use the os.path.split(path)
function to split the pathname path
into a pair; (head, tail)
.
这两个函数都使用os.path.split(path)函数将路径名路径拆分为一对; (头,尾)。
The os.path.dirname(path)
function returns the head of the path.
os.path.dirname(path)函数返回路径的头部。
E.g.: The dirname of '/foo/bar/item'
is '/foo/bar'
.
例如:'/ foo / bar / item'的目录是'/ foo / bar'。
The os.path.basename(path)
function returns the tail of the path.
os.path.basename(path)函数返回路径的尾部。
E.g.: The basename of '/foo/bar/item'
returns 'item'
例如:'/ foo / bar / item'的基本名称返回'item'
From: http://docs.python.org/2/library/os.path.html#os.path.basename
来自:http://docs.python.org/2/library/os.path.html#os.path.basename