初学python求助:IndexError: list index out of range

hahaha170127 2018-08-20 12:57:32
使用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
请问如何破解?
...全文
762 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

493

社区成员

发帖
与我相关
我的任务
社区描述
硬件使用 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧