2
"""Script which takes one or more file paths and reports on their detected
7
% chardetect.py somefile someotherfile
11
If no paths are provided, it takes its input from stdin.
13
It was properly modified to fit with scratch text editor project.
14
Original version was from the creators of python-chardet.
17
from sys import argv, stdin
19
from chardet.universaldetector import UniversalDetector
22
def encoding_of(file, name='stdin'):
23
"""Return a string describing the probable encoding of a file."""
24
u = UniversalDetector()
29
if result['encoding']:
30
return result['encoding'].upper ()
37
print description_of(stdin)
40
print encoding_of(open(path, 'rb'), path)
43
if __name__ == '__main__':