How to determine the encoding of text?

前端 未结 10 1468
一向
一向 2020-11-21 07:47

I received some text that is encoded, but I don\'t know what charset was used. Is there a way to determine the encoding of a text file using Python? How can I detect the enc

10条回答
  •  清酒与你
    2020-11-21 08:08

    This might be helpful

    from bs4 import UnicodeDammit
    with open('automate_data/billboard.csv', 'rb') as file:
       content = file.read()
    
    suggestion = UnicodeDammit(content)
    suggestion.original_encoding
    #'iso-8859-1'
    

提交回复
热议问题