I would like to be able to take a file that does not have a file extension and determine what mime type it is by using its magic numbers. Below is the solution using the filetype library solution that works fine. Is there another way to do it?
https://pypi.org/project/filetype/
import filetype def main(): kind = filetype.guess('collatz') if kind is None: print('Cannot guess file type!') return print('File extension: %s' % kind.extension) print('File MIME type: %s' % kind.mime) print(kind) if __name__ == '__main__': main()
2.1m questions
2.1m answers
60 comments
57.0k users