python程序错误IndexError: list index out of range

go3611190 2015-02-16 01:55:33
新学习python这个问题总是没法解决希望大家帮帮忙
源码:
#! /usr/bin/env python
#coding=utf-8
import time
import os
str1 = open( r'C:\Users\python\Desktop\url.txt' ,'r').readlines()
num = 0
while num <= len(str1):
com =r'"D:\Program Files (x86)\Mozilla Firefox\firefox.exe" %s'%(str1[num])
print com
os.system(com)
num = num +1
time.sleep(2)
else:
print 'url open end!!!!'



Traceback (most recent call last):
File "D:\python_work\python\python\url.py", line 8, in <module>
com =r'"D:\Program Files (x86)\Mozilla Firefox\firefox.exe" %s'%(str1[num])
IndexError: list index out of range
...全文
13313 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
djx404 2017-05-18
  • 打赏
  • 举报
回复
引用 6楼qq_28304687 的回复:
你没有输入参数
test1234
苏酒酒 2016-12-09
  • 打赏
  • 举报
回复
你没有输入参数
iasky 2015-03-03
  • 打赏
  • 举报
回复
while越界了。
  • 打赏
  • 举报
回复
while num < len(str1): 序列的下标是 从0开始到 最大行数-1
DarkChampion 2015-02-16
  • 打赏
  • 举报
回复
另外,os.system(com)可能会阻塞,最好用process
DarkChampion 2015-02-16
  • 打赏
  • 举报
回复
while num <= len(str1):
改成
while num < len(str1):
map98 2015-02-16
  • 打赏
  • 举报
回复
url.txt 是个空文件。

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

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