A solution unrelated to Python, but which may be useful for those who, like myself, land here from a search.
Use exiftool
directly in the shell:
exiftool -exif -if '$exif' $YourFile
The -Exif
property given by exiftool
obviously only exists if the file does have Exif metadata. The -if
condition will give non-zero exit status if the property does not exist.
Depending on if the file contains an Exif part, it will output either something like
EXIF : (Binary data 23929 bytes, use -b option to extract)
or
1 files failed condition
To use it in a script, and just use the exit code, without any output from exiftool itself:
if exiftool -exif -if '$exif' "$YourFile" >/dev/null; then
echo "Yes. Exif found in $YourFile"
else
echo "No Exif in $YourFile"
fi