当前位置:   article > 正文

python: tuple index out of range_pyhton tuple index out of range

pyhton tuple index out of range

问题描述:在进行Excel操作时,想要对Excle进行批量赋值,此时使用

                  for i in range(0,9):
                        ws["C"][i].value = i

在运行时,提示 tuple index out of range错误。

原因:元组超出索引范围,在Excle中,其单元格表示为A[1]、A[2]等,是一维数组,上面的表示ws["C"][i]是二维数组,所示会提示错误。

解决方法:使用一维数组即可。

             for i in range(1,10):
                   ws["C"+str(i)].value = i

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号