UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 7240: character maps to

前端 未结 3 1059
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 16:57

I am student doing my master thesis. As part of my thesis, I am working with python. I am reading a log file of .csv format and writing the ext

3条回答
  •  时光说笑
    2020-12-10 17:31

    with open('input.tsv','rb') as f:
    for ln in f:
        decoded=False
        line=''
        for cp in ('cp1252', 'cp850','utf-8','utf8'):
            try:
                line = ln.decode(cp)
                decoded=True
                break
            except UnicodeDecodeError:
                pass
        if decoded:
            # use 'line'
    

提交回复
热议问题