首页 > 解决方案 > 分割线函数出现 Python 索引错误

问题描述

以下 Python 代码在第 17 行给我一个索引错误,version = result[marker:].splitlines()[0]:

import os, math, sys

#OS_bit = (round(math.log(sys.maxint,2)+1)) # get the bit

os.system("sudo apt-get install python-pip && sudo apt-get install tor") # installing dependencies
os.system("pip install -U selenium")
os.system("pip install Pysocks")
os.system("pip install pyvirtualdisplay && apt-get install xvfb")

#print("\n \n {} \n \n".format(OS_bit))

os.system('firefox -v > tmp') 
result = open('tmp', 'r').read()
print (result)
marker = result.find('Firefox') + 8 
print (marker)
version = result[marker:].splitlines()[0] 
print (version)
a,b,c = version.split(".") 
os.remove('tmp') 

版本 = 结果[标记:].splitlines()[0]

IndexError:列表索引超出范围

不知道如何解决。有什么可以分享的快速课程吗?谢谢。

标签: pythonpython-3.xsyntaxindex-error

解决方案


问题在于结果,结果不是一个列表,它只是一个赋值变量,所以这就是你看到IndexError: list index out of range.


推荐阅读