import xlrd import os def f_sig_val(xls_path, output_path): des_xls = xlrd.open_workbook(xls_path + "/" + file_name).sheet_by_index(1) input_sig = [str(des_xls.cell(0, i).value) for i in range(2, des_xls.ncols)] output_sig = [str(des_xls.cell(i, 0).value) for i in range(20, des_xls.nrows)] sig_val = [[str(des_xls.cell(i, j).value) for i in range(20, des_xls.nrows) if str(des_xls.cell(i, j).value) != ""] for j in range(2, des_xls.ncols)] width = [] print(des_xls.nrows) print(des_xls.ncols) for i in input_sig: print(i) for i in output_sig: print(i) print(sig_val) texts = gen_code(input_sig, output_sig, sig_val) write_to_svfile(output_path+"/test.sv", texts, "w") def gen_code(input_sig, output_sig, sig_val): texts = [] for i in range(len(sig_val)): texts.append(4*""+"if ("+input_sig[i]+" == 1)") for j in range(len(sig_val[i])): texts.append(8*""+output_sig[i]+" = "+sig_val[i,j]+";") return texts def write_to_svfile(svfile_name, texts, method): sv_file = open(svfile_name, "%s"%method) for i in texts: sv_file.write(i+"\n") sv_file.close() xls_path = "." output_path = "." file_name = "glb_ctrl_modesel.xlsx" f_sig_val(xls_path, output_path) 语法错误
时间: 2024-04-23 21:23:15 浏览: 50
Read data from the Excel spreadsheet.zip_Spreadsheet::Read_excel
这段代码可能存在语法错误,因为它没有正确的缩进。在 Python 中,缩进是非常重要的,因为它用于标识代码块的开始和结束。在这段代码中,函数定义和函数调用之间的空格也可能导致语法错误。为了避免这种问题,建议使用编辑器或集成开发环境(IDE)来编写和格式化 Python 代码。同时,建议在编写代码时遵循 PEP 8 规范,这是 Python 官方推荐的代码风格指南,可以提高代码的可读性和可维护性。
阅读全文