python - 分割线函数出现 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:列表索引超出范围
不知道如何解决。有什么可以分享的快速课程吗?谢谢。
解决方案
问题在于结果,结果不是一个列表,它只是一个赋值变量,所以这就是你看到IndexError: list index out of range
.
推荐阅读
- c# - 在独立的 exe 中嵌入字体
- python-3.x - Azure 应用服务上的 Web2py 项目部署
- php - Windows 10 上的 XAMPP 未运行 php
- python - 更改掷骰子的输出文本
- java - 在分页库中,PagedList 值为 null
- java - 使用乐观锁定在多对多父子关系中并行添加子代
- linux - 如何增加kafka集群上的打开文件
- android - Android Room 使用 DataSource.Factory 时如何按文本搜索?
- django - Django计算多个对象内2个字段的平均值
- nunit - 在哪里可以找到 Nunit xml 解析器