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("{},\"{}\"\n".format(info[0],info[1].replace("\n","").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("{},\"{}\"\n".format(info[0],info[1].replace("\n","").replace(" ","")))
fout.close()

解决方法:

fout = open('job_desc.txt', 'wt',encoding='utf-8')
for info in job_desc:
    fout.write("{},\"{}\"\n".format(info[0],info[1].replace("\n","").replace(" ","")))
fout.close()

 

相关文章:

  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2021-09-13
猜你喜欢
  • 2022-02-04
  • 2022-02-09
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-09-02
相关资源
相似解决方案