打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python: TypeError: 'generator' object is not subscriptable 解决方法

Python: TypeError: ‘generator’ object is not subscriptable 解决方法

>>> import openpyxl>>> wb = openpyxl.load_workbook('.\\省一模考场安排.xlsx')>>> sheet = wb.get_active_sheet()>>> sheet<Worksheet "Sheet1"><Cell 'Sheet1'.E1>>>> sheet.cell(row=1,column=5).value'姓名'>>> sheet.columns[1]** Traceback (most recent call last):  File "<pyshell#194>", line 1, in <module>    sheet.columns[1]TypeError: 'generator' object is not subscriptable**

运行后,遇到如下的错误,

TypeError: 'generator' object is not subscriptable

问题分析:书本上的代码是基于openpyxl 2.3.3. 后续openpyxl版本对.column的方法的方法已有所改进。

可行的解决方法:
(1) 借助列表的方法, list(sheet.columns)[2]
(2) 借助列字母, sheet[“B”]

以上两种方法得到的数据类型都是元组,<class ‘tuple’>。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Python中利用openpyxl读取Excel文件
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
python生成excel文件的三种方式
Python 操作 excel
Python读取Excel文件的方法
python编程操作office三剑客之Excel篇
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服