Here are choosing to use filetype get the type of file.
Before using filetype, first with pip install filetype.
! # / usr / bin / to python3 Import filetype Import argparse Import SYS DEF get_parameter (): Parser = argparse.ArgumentParser (Description = 'Get the type of the script file') parser.add_argument ( '- F', dest = ' inputFile ', type = str, default =' ', help =' input file to be detected ') args = parser.parse_args () inputFile = args.inputFile return inputFile DEF main (): inputFile = get_parameter () IF inputFile ==' ': Print (' enter file to be detected ') the sys.exit (. 1) FT1 = filetype.guess (inputFile) IF None FT1 IS: Print (' can not determine the file type ') Print (' file extension: { } '. the format (ft1.extension)) Print ('File type:. {} 'Format (ft1.mime)) if __name__=='__main__': main()
This script environment python3 environment