import xlwt import random book = xlwt.Workbook(encoding='utf-8', style_compression=0) sheet = book.add_sheet('sheet1', cell_overwrite_ok=True) col = ['sram_config', 'word', 'io', 'area(um^2)'] word_depth_list = [] io_list = [] word_depth_list.append(list(range(32, 1025, 16)) + list(range(1056, 8193, 16))) io_list.append(list(range(16, 145, 1))) max_1 = len(word_depth_list[0]) max_2 = len(io_list[0]) col_max = max_1 * max_2 print(col_max) for i in range(0, int(len(col))): sheet.write(0, i, col[i]) col = 1 while col < col_max: for i in word_depth_list[0]: for j in io_list[0]: sheet.write(col, 0, str(i) + 'x' + str(j)) sheet.write(col, 1, i) sheet.write(col, 2, j) sheet.write(col, 3, random.uniform(0, 1)) col = col + 1 book.save('C:\\Users\\Wei_Li\\Desktop\\example.xlsx') 找出其中的错误并改正。
时间: 2023-04-03 12:02:52 浏览: 245
在代码中,第6行的代码缺少一个右括号,应该修改为:
word_depth_list.append(list(range(32, 1025, 16)) + list(range(1056, 8193, 16)))
另外,在第21行的代码中,应该将“col = col + 1”修改为“col += 1”,或者直接写成“col += 1”。修改后的代码如下:
import xlwt
import random
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
col = ['sram_config', 'word', 'io', 'area(um^2)']
word_depth_list = []
io_list = []
word_depth_list.append(list(range(32, 1025, 16)) + list(range(1056, 8193, 16)))
io_list.append(list(range(16, 145, 1)))
max_1 = len(word_depth_list[0])
max_2 = len(io_list[0])
col_max = max_1 * max_2
print(col_max)
for i in range(0, int(len(col))):
sheet.write(0, i, col[i])
col = 1
while col < col_max:
for i in word_depth_list[0]:
for j in io_list[0]:
sheet.write(col, 0, str(i) + 'x' + str(j))
sheet.write(col, 1, i)
sheet.write(col, 2, j)
sheet.write(col, 3, random.uniform(0, 1))
col += 1
book.save('C:\\Users\\Wei_Li\\Desktop\\example.xlsx')
阅读全文