解决 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,如需转载请自行联系原作者

相关文章
|
5月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
385 100
|
5月前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
533 99
|
5月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
5月前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
5月前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
5月前
|
Python
使用Python f-strings实现更优雅的字符串格式化
使用Python f-strings实现更优雅的字符串格式化
|
6月前
|
索引 Python
python 字符串的所有基础知识
python 字符串的所有基础知识
403 0
|
6月前
|
Python
Python字符串center()方法详解 - 实现字符串居中对齐的完整指南
Python的`center()`方法用于将字符串居中,并通过指定宽度和填充字符美化输出格式,常用于文本对齐、标题及表格设计。
|
6月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
364 92

推荐镜像

更多