ospathsplitoriginal_file_path1-4
The expression os.path.split(original_file_path)[1][:-4] will return the filename of the file at original_file_path without the file extension.
Here's a breakdown of what the expression does:
-
os.path.split(original_file_path)splits theoriginal_file_pathinto a directory path and the filename. It returns a tuple containing both values.os.path.split('/path/to/file.txt')will return('/path/to', 'file.txt').
-
[1]accesses the second element of the tuple, which is the filename.('/path/to', 'file.txt')[1]will return'file.txt'.
-
[:-4]slices the filename string to remove the last 4 characters (which would be the file extension).'file.txt'[:-4]will return'file'.
So, the overall expression os.path.split(original_file_path)[1][:-4] will return the filename without the file extension
原文地址: https://www.cveoy.top/t/topic/izQk 著作权归作者所有。请勿转载和采集!