這里選擇使用使用filetype獲取檔案的型別,
使用filetype之前,先用pip安裝filetype,
#!/usr/bin/python3
import filetype
import argparse
import sys
def get_parameter():
parser=argparse.ArgumentParser(description='該腳本用于獲取檔案的型別')
parser.add_argument('-f',dest='inputFile',type=str,default='',help='輸入待檢測檔案')
args=parser.parse_args()
inputFile=args.inputFile
return inputFile
def main():
inputFile=get_parameter()
if inputFile=='':
print('請輸入待檢測檔案')
sys.exit(1)
ft1=filetype.guess(inputFile)
if ft1 is None:
print('無法判斷該檔案型別')
print('檔案擴展名為:{}'.format(ft1.extension))
print('檔案型別為:{}'.format(ft1.mime))
if __name__=='__main__':
main()
本腳本運行環境為python3環境,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/162034.html
標籤:Python
上一篇:使用scrapy-selenium, chrome-headless抓取動態網頁
下一篇:Python-Flask
