我真的认为我知道答案,而且是:
current_working_directory = os.getcwd().split("/")
local_working_directory = current_working_directory[len(current_working_directory)-1]
这对我有用。我看过的其他帖子(例如:findcurrentdirectory和file'sdirectory)似乎都没有解释如何获得本地目录,而不是整个目录路径。所以把这个贴在已经回答的问题上。也许问题应该是:我如何发布我已经回答过的问题的答案,以便帮助其他人?嘿,也许还有更好的答案:-)
我会使用
basename
os.path
包含许多有用的路径操作函数。我想你在找os.path.basename
。最好使用os.path
,因为您的程序将是跨平台的:目前,您的解决方案不适用于Windows。跨平台获取目录名的方法是试试这些
从这里拍摄:Find current directory and file's directory
编辑:这是另一个问题
^{pr2}$相关问题 更多 >
编程相关推荐