import xlrd file_path = r"E:\11桌面\测试文件积极\1.xls" sheet_index = 0 data = xlrd.open_workbook(file_path) table = data.sheet_by_index(sheet_index) rownum = table.nrows colnum = table.ncols double_list = [] i=0 while table.cell(i,0).value == 0: double_list[i].append(table.row_values(i)) i += 1 print(double_list)
以上是代码部分,结果就如下图所示:
用了for循环和while循环都不得行,在循环以外都可以正常赋值,但是放在循环中就不行了。
请求大佬解救MAYDAY!MAYDAY!MAYDAY!
你不能上来就使用double_list[i].append函数吧,得先对数组元素做一个初始化。 double_list[i] = " " ;