How to get file extension

anonymity
Release: 2019-05-25 09:47:25
Original
5303 people have browsed it

How to get the file extension?

First analyze the problem:

How to get file extension

#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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!