Original link: https://blog.csdn.net/shijing_0214/article/details/51971734
When using python, often have problems of text encoding, the most common is the " 'gbk' codec can not decode byte 0xad in position 12: illegal multibyte sequence".
Solution: "gbk" may be converted to utf8 so used.
- In the text, when open, set the encoding format open ( '1.txt', encoding = 'gbk')
- If the first step does not resolve, it may be there are some special text characters beyond the scope gbk coding, you can use more extensive coding "gb18030", such as: open ( "1.txt", encoding = 'gb18030' )
- If not enough, then the second, ha, there is a third method, it can be used 'ignore' attribute is ignored. open ( '1.txt', encoding = 'gb18030', errors = 'ignore');
- There is also a common solution for the open ( '1.txt'). Read (). Decode ( 'gb18030', 'ignore')