python - 无法遍历列表 - Openpyxl
问题描述
我无法遍历数据行(我保存到列表中)。
下面是示例代码
Timelist = []
for row_cells in sheetname.iter_rows(min_col=1,max_col=6,min_row=2):
Timelist = row_cells[1].value
for x in Timelist:
print(x)
我想遍历该列的行值(在本例中为第 1 列)
解决方案
您可能希望将值附加到Timelist
for 循环内的列表中,而不是分配,以便以后能够对其进行迭代以进行打印x
Timelist = []
for row_cells in sheetname.iter_rows(min_col=1,max_col=6,min_row=2):
Timelist.append(row_cells[1].value) # <--- append here
for x in Timelist:
print(x)
推荐阅读
- r - Rotate Lines To True North or Vertical
- c# - 类的新实例中的属性和先前创建的同一类实例中的属性被引用相同的内存
- html - 为什么 CSS 文件不会改变 Django 项目中 HTML 标签的颜色?
- php - 如何检查订单商品是否有元字段“延期交货”?
- java - AnimatedVectorDrawable 抛出 UnsupportedOperationException
- c++ - 实现模板类 Stack1
- php - /^a|b|c$/ 和 /^a$|^b$|^c$/ 之间的预置差异
- mysql - 如何将 SQL 查询转换为 JSON 格式
- python - 如何在给定字符串名称的情况下导入文件?
- visual-studio-code - 有没有办法对vscode状态栏进行颜色编码