How to get the file extension?
First analyze the problem:
#The file extension form is separated by "." after the file path, so we can use Python's string interception Select to get the file extension.
def get_file_extension(filename): arr = os.path.splitext(filename) return arr[len(arr) - 1] #return arr[len(arr) - 1].replace(".","") 可以将结果中的.去掉 print(get_file_extension("abc.jpg")) #返回 .jpg print(get_file_extension("2014.01.25.gif")) #返回 .gif
The above is the detailed content of How to get file extension. For more information, please follow other related articles on the PHP Chinese website!