解决 python用 xlsxwrite 向excel 中写入中文字符串变量 报错

简介:

问题:  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 7: ordinal not in range(128)


分析:在网上查找,原来python的str默认是ascii编码,和unicode编码冲突,所以无法 中文字符串变量写入excel。


解决:在代码中加入下面几行就可以了。

import sys
reload(sys)
sys.setdefaultencoding('utf8')





      本文转自独弹古调  51CTO博客,原文链接:http://blog.51cto.com/hunkz/1697345,如需转载请自行联系原作者

相关文章
|
11月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
573 100
|
11月前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
682 99
|
11月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
11月前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
11月前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
11月前
|
Python
使用Python f-strings实现更优雅的字符串格式化
使用Python f-strings实现更优雅的字符串格式化
|
索引 Python
python 字符串的所有基础知识
python 字符串的所有基础知识
548 0
|
12月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
547 92
|
11月前
|
异构计算 Python
ERROR: pip’s dependency resolver does not currently take into 报错-Python项目依赖冲突的解决方案-优雅草优雅草卓伊凡
ERROR: pip’s dependency resolver does not currently take into 报错-Python项目依赖冲突的解决方案-优雅草优雅草卓伊凡
845 1

推荐镜像

更多