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 ('').
^{} 是你要找的-
确保将
r
放在字符串前面,以便将其视为原始字符串。演示-
如果您只想} 与上面的一起使用,例如-
folder2
,可以将^{演示-
你想用dirname。如果您只需要一个目录,可以使用os.path.basename
综合起来,它看起来是这样的:
这会让你成为“另一个副局长”
下面不是理想的方法,但我最初建议使用os.path.split,并简单地获得最后一项。可能是这样的:
您可以使用^{} :
给定完整路径,然后可以正常分割以获得路径的最后一部分。例如,通过使用^{} :
一起:
相关问题 更多 >
编程相关推荐