def detect_encoding(filename):
    detector = UniversalDetector()
    with open(filename, 'rb') as unknown_file:
        for line in unknown_file:
            detector.feed(line)
            if detector.done:
                break
    detector.close()

    return detector.result['encoding']
Takes a filename and attempts to detect the character encoding of the file
dataset/ETHPy150Open inpho/topic-explorer/topicexplorer/langspace.py/detect_encoding