当前位置: 首页 > news >正文

Python错误集锦:xlwt写入表格时提示exception-unexpected-data-type-class-bytes

原文链接:http://www.juzicode.com/python-error-exception-unexpected-data-type-class-bytes

错误提示:

#juzicode.com/VX公众号:juzicode
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('juzicode')
a = b'juzicode'
ws.write(3, 0, '桔子code')
ws.write(3, 1, a)  #bytes
==========运行结果:
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[9], line 75 a = b'juzicode'6 ws.write(3, 0, '桔子code') #str
----> 7 ws.write(3, 1, a)  #bytesFile D:\Python\Python310\lib\site-packages\xlwt\Worksheet.py:1088, in Worksheet.write(self, r, c, label, style)1035 def write(self, r, c, label="", style=Style.default_style):1036     """1037     This method is used to write a cell to a :class:`Worksheet`.1038 (...)1086        :class:`~xlwt.Style.XFStyle` object.1087     """
-> 1088     self.row(r).write(c, label, style)File D:\Python\Python310\lib\site-packages\xlwt\Row.py:254, in Row.write(self, col, label, style)252     self.__rich_text_helper(col, label, style, style_index)253 else:
--> 254     raise Exception("Unexpected data type %r" % type(label))Exception: Unexpected data type <class 'bytes'>

错误原因:

1、xlwt写入表格的数据类型不能为bytes

解决方法:

1、将bytes类型更换为str类型:

#juzicode.com/VX公众号:juzicode
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('juzicode')
a = b'juzicode'
ws.write(3, 0, '桔子code') #str
ws.write(3, 1, str(a))  #bytes

http://www.lryc.cn/news/353805.html

相关文章:

  • 赶紧收藏!2024 年最常见 20道 Redis面试题(八)
  • Flowable第一次启动MYSQL8.0版本(踩坑)
  • Java基础的语法---StringBuilder
  • 【微服务】springboot 构建镜像多种模式使用详解
  • 手写tomcat(Ⅲ)——tomcat动态资源的获取
  • 软件测试面试题(四)
  • infoq学习笔记-云原生网关当道,三大主流厂商如何“竞 技”?
  • Python中别再用 ‘+‘ 拼接字符串了!
  • 前端上传heic图片转jpe格式并展示
  • VMware虚拟机-设置系统网络IP、快照、克隆
  • 指纹识别概念解析
  • 图像处理神经网络数据预处理步骤的详细解释和分析
  • 音视频开发4-补充 FFmpeg 开发环境搭建 -- 在windows 上重新build ffmpeg
  • 第十二周笔记
  • SketchUp v2024 v24.0.553 解锁版安装教程 (强大的绘图三维建模工具)
  • 力扣题解记录
  • Flutter 中的 ExpandIcon 小部件:全面指南
  • 想转行程序员的朋友,有什么想问的在评论区随便问,我知道的都告诉你。
  • Jenkins工具系列 —— 通过钉钉API 发送消息
  • MySQL--存储引擎
  • 【经典文献】光-声立体成像:关于系统标定与三维目标重建
  • 弘君资本股市行情:股指预计保持震荡上扬格局 关注汽车、银行等板块
  • 看这两位东北圣女美吗?如何描写美女的大长腿?
  • Linux相关指令
  • 自建公式,VBA在Excel中解一元一次方程
  • Linux-之 简易:Shell编程
  • vue3的api风格
  • MySQL 开源到商业(五):开源 vs 养家糊口
  • 进程信号(1)
  • Pytorch入门(7)—— 梯度累加(Gradient Accumulation)