【发布时间】:2017-04-12 04:08:08
【问题描述】:
我有一个名为dllName 的变量,它获取已执行的dll 的名称。有时此 dll 以"kernel32.dll" 的格式返回,有时以"C:\Windows\system32\kernel32.dll" 的格式返回。
路径可能不同,我想要实现的是剥离"C:\Windows\system32\"。
编辑:Extract file name from path, no matter what the os/path format
我的问题和这个问题不一样,因为 os.path.basename 和 os.path.split 在这种情况下不起作用。
对于 os.path.split,头部为空,尾部包含整个路径?
【问题讨论】:
-
不需要正则表达式,只需使用
os.path.basename -
您能告诉我们您尝试过哪些不起作用或遇到困难的方法吗?如果您自己还没有尝试过任何代码,您可以使用 stackoverflow 上的搜索功能吗?
-
@Rawing:
os.path.basename不适用于 Linux 上的 Windows 路径。
标签: python python-2.7 split