You can import os
but os.path.It's a little strange that I can't write bassname
.
Maybe it's because you took a weird approach, so try it this way
from os.path import basename
print basename("/a/b/c.txt")
os.path.To remove the extension without using basename
, you must use os.path.splitext(path).
os.path.splitext(path)
divides the path of the file by (root, ext) (but root+ext = path)
ext is either an empty string or a string containing one maximum point (only the last ext2 split if path is myfile.ext1.ext2)
And if path starts with a point (.myfile), the beginning is included in root.
import os
print os.path.splitext("path_to_file")[0]
There is.
© 2024 OneMinuteCode. All rights reserved.