UnicodeEncodeError Traceback (most recent call last) <ipython-input-95-45a7accf2da0> in <module> 1 fout = open('job_desc.txt', 'wt') 2 for info in job_desc: ----> 3 fout.write("{},"{}" ".format(info[0],info[1].replace(" ","").replace(" ",""))) 4 fout.close() UnicodeEncodeError: 'gbk' codec can't encode character 'xa0' in position 134: illegal multibyte sequence
运行代码如下,报错如上
fout = open('job_desc.txt', 'wt') for info in job_desc: fout.write("{},"{}" ".format(info[0],info[1].replace(" ","").replace(" ",""))) fout.close()
解决方法:
fout = open('job_desc.txt', 'wt',encoding='utf-8') for info in job_desc: fout.write("{},"{}" ".format(info[0],info[1].replace(" ","").replace(" ",""))) fout.close()