you can use python magic
Although this module is in PyPi, the name conflicts with other packages of the same name, so you have to download and install the wheel
To do this:
Once you have that package installed, use the following code to find file type:
It will return a string of type:
Although this module is in PyPi, the name conflicts with other packages of the same name, so you have to download and install the wheel
To do this:
- Get the wheel from PyPi as follows
- go to: https://pypi.python.org/pypi/python-magic/
- Download the wheel file (Current version): python_magic-0.4.15-py2.py3-none-any.whl
- change directory to one containing wheel
- from command line, install with:
pip install python_magic-0.4.15-py2.py3-none-any.whl
Once you have that package installed, use the following code to find file type:
def check_filetype(filename): f = magic.Magic(mime=True, uncompress=True, filename) return f.from_file(filename)This will avoid having to load entire zip file.
It will return a string of type:
Output:'text/plain'
See the documentation here: https://github.com/ahupp/python-magic