解决Python字符串问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position问题

xiaoxiao2021-02-28  66

再向文件写入中文字符串会出现这个问题。即使在开头添加了# -- coding: utf-8 --也不行。 解决办法: import sys reload(sys) sys.setdefaultencoding( “utf-8” ) 这样可以成功运行。

转载请注明原文地址: https://www.6miu.com/read-71940.html

最新回复(0)