1

我正在尝试使用ntpath.basename()/Users/user/file_one和 get一样的字符串file_one。但是,我遇到了问题ntpath。它在我运行脚本时有效,但在我 py2app 之后,ntpath 不再有效。ntpath 有替代方案吗?我不确定它对 Windows 有什么特殊功能,但我的脚本是为 OS X 构建的,因此只使用正斜杠,所以如果没有 ntpath 提供的“NT 魔法”,我应该没问题。

4

1 回答 1

3
>>> import os
>>> print(os.path.split('/Users/user/file_one')[1])
file_one
>>> print(os.path.basename('/Users/user/file_one'))
file_one
于 2013-01-20T16:22:29.243 回答