I'm trying to use ntpath.basename()
to take a string like /Users/user/file_one
and get file_one
. However, I'm having problems with ntpath
. It works when I run the script, but after I py2app it, ntpath no longer works. Is there an alternative to ntpath? I'm not sure what special features it has for Windows, but my script is build for OS X, and therefore only uses forward slashes, so I should be fine without the "NT magic" that ntpath offers.
Asked
Active
Viewed 5,175 times
1

tkbx
- 15,602
- 32
- 87
- 122
-
2After `py2app`-ing, can you still access `os.path.basename`? – DSM Jan 20 '13 at 16:05
-
1Why would you use `ntpath` on a POSIX path? – Ignacio Vazquez-Abrams Jan 20 '13 at 16:13
-
@IgnacioVazquez-Abrams http://stackoverflow.com/questions/8384737/python-extract-file-name-from-path-no-matter-what-the-os-path-format – tkbx Jan 20 '13 at 16:14
-
@DSM that works perfectly, you might want to make that an answer. – tkbx Jan 20 '13 at 16:19
1 Answers
3
>>> import os
>>> print(os.path.split('/Users/user/file_one')[1])
file_one
>>> print(os.path.basename('/Users/user/file_one'))
file_one

tiago
- 22,602
- 12
- 72
- 88