- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the mime type of a file in Python?
Python has a module called mimetypes that you can use to guess the mime type of a file in Python. However it is not a reliable way to know the mime type of a file.
>>> import mimetypes >>> print(mimetypes.MimeTypes().guess_type('my_file.txt')) text/plain
You can also use a non-standard module called python-magic to deduce the mimetype of a file.
>>> import magic >>> mime = magic.Magic(mime=True) >>> mime.from_file("my_file.txt") text/plain
- How to detect the content type of a file in Golang?
- How do we specify MIME type in Asp.Net WebAPI C#?
- How to find a file using Python?
- How to Find Hash of File using Python?
- Determine type of sound file using Python (sndhdr)
- Find the minimal data type of a scalar value in Python
- How to check the permissions of a file using Python?
- How to change the permission of a file using Python?
- How to change the mode of a file using Python?
- How to change the owner of a file using Python?
- How to extract a part of the file path (a directory) in Python?
- How to find the file using C#?
- How to find the file using Java?
- Find the minimal data type of an array-like in Python
- How to create a duplicate file of an existing file using Python?