初学python求助:IndexError: list index out of range
使用spyder:源文件为
#!/usr/bin/env python3
import sys
from xlrd import open_workbook
from xlwt import Workbook
input_file = sys.argv[1]
output_file = sys.argv[2]
output_workbook = Workbook()
output_worksheet = output_workbook.add_sheet('jan_2013_output')
with open_workbook(input_file) as workbook:
worksheet = workbook.sheet_by_name('january_2013')
for row_index in range(worksheet.nrows):
for column_index in range(worksheet.ncols):
output_worksheet.write(row_index, column_index, worksheet.cell_value(row_index, column_index))
output_workbook.save(output_file)
执行: python 2excel_parsing_and_write.py sales_2013.xlsx output_files\2output.xls
输出:
runfile('C:/Users/Administrator/Desktop/Python数据分析基础/excel/2excel_parsing_and_write.py', args='sales_2013.xlsx')
Traceback (most recent call last):
File "<ipython-input-23-85820af6f079>", line 1, in <module>
runfile('C:/Users/Administrator/Desktop/Python数据分析基础/excel/2excel_parsing_and_write.py', args='sales_2013.xlsx')
File "H:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "H:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Administrator/Desktop/Python数据分析基础/excel/2excel_parsing_and_write.py", line 7, in <module>
output_file = sys.argv[2]
IndexError: list index out of range
请问如何破解?