How to identify file type

PHOTO EMBED

Tue Feb 14 2023 16:11:56 GMT+0000 (Coordinated Universal Time)

Saved by @praveenms079 #python #plotly

import magic

filename = '/home/jovyan/pi-ml/data/images/'+'W074FLEB9138.tiff'

# Open the file in binary mode
with open(filename, 'rb') as f:
    # Create a magic object 
    magic_obj = magic.Magic()

    # Use magic to identify the file type
    file_type = magic_obj.from_buffer(f.read())

print(file_type)
content_copyCOPY