python-magic¶
python-magic is the recommended library to use for checking whether a file is a text file.
In [2]:
!pip3 install python-magic
In [3]:
import magic
In [4]:
f = magic.Magic(mime=True, uncompress=True)
In [2]:
!wget https://user-images.githubusercontent.com/824507/128439087-0c935d86-bb34-4c2c-8e69-6d78b3022833.png -O 4s.jpg
In [5]:
f.from_file("4s.jpg")
Out[5]:
In [1]:
!wget https://storage.googleapis.com/erwinh-public-data/bankingdata/bank-full.csv
In [6]:
f.from_file("bank-full.csv")
Out[6]:
binaryornot¶
Not maintained actively.
In [ ]:
from binaryornot.check import is_binary
In [ ]:
is_binary("README.rst")
In [ ]: