mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
20 lines
504 B
Python
20 lines
504 B
Python
from chardet.universaldetector import UniversalDetector
|
|
import sys, glob
|
|
|
|
count = 0
|
|
u = UniversalDetector()
|
|
for f in glob.glob(sys.argv[1]):
|
|
print(f.ljust(60), end=' ')
|
|
u.reset()
|
|
for line in open(f, 'rb'):
|
|
u.feed(line)
|
|
if u.done: break
|
|
u.close()
|
|
result = u.result
|
|
if result['encoding']:
|
|
print(result['encoding'], 'with confidence', result['confidence'])
|
|
else:
|
|
print('******** no result')
|
|
count += 1
|
|
print(count, 'tests')
|