Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

python - Is there another way to determine a file's mime type by using the magic numbers?

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()
question from:https://stackoverflow.com/questions/65832894/is-there-another-way-to-determine-a-files-mime-type-by-using-the-magic-numbers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...