def guess_encoding(csv_file):
    """guess the encoding of the given file"""
    with open(csv_file, "rb") as f:
        data = f.read(5)
    if data.startswith(b"\xEF\xBB\xBF"):  # UTF-8 with a "BOM" (normally no BOM in utf-8)
        return ["utf-8-sig"]
    try:
        with open(csv_file, encoding="utf-8") as f:
            preview = f.read(222222)
            return ["utf-8"]
    except:
        return [locale.getdefaultlocale()[1], "utf-8"]
guess the encoding of the given file
winpython/utils.py