gpt4 book ai didi

python - Python 是否具有与 Unix basename 相等的 basename 函数?

转载 作者:行者123 更新时间:2023-12-04 12:17:57 27 4
gpt4 key购买 nike

>>> os.path.basename("../dir/")
''
$ basename ../dir/
dir
documentation

os.path.basename(path)

Return the base name of pathname path. This is the second element of the pair returned by passing path to the function split(). Note that the result of this function is different from the Unix basename program; where basename for '/foo/bar/' returns 'bar', the basename() function returns an empty string ('').


有没有与 Unix basename 没有区别的函数?

最佳答案

不是一个功能,AFAIK,但这并不难。只需先删除尾部斜杠:

os.path.basename(os.path.normpath("../dir/"))

关于python - Python 是否具有与 Unix basename 相等的 basename 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67496196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com