Searching the name of the C library (libmagic
) used for the file
command, nets 3 interesting python packages on PyPI:
- libmagic (bitbucket repo)
- python-magic (you can find some documentation in the github repo)
- filemagic (github repo)
Question
I want to check if a given file's extension is correct or not. For example, someone give me a file with an extension .zip but actually it may be an executable.
Using mimetypes
I could not determine a file's real type. As far as I see, mimetypes
needs an extension.
I can map the output of unix file
command with some extensions. Even if you change the extension, you cannot deceive file
command. However, this solution needs a subprocess.
I thought, there may be a more pythonic solution of this problem. Does anyone know?
La solution
Searching the name of the C library (libmagic
) used for the file
command, nets 3 interesting python packages on PyPI:
Autres conseils
Ultimately, there is no absolute way of knowing. For several reasons:
I'm afraid you will need to be content with a partial answer like the ones you already have.