python - 特定行 [8] 的 CSV 解析错误:列表索引超出范围
问题描述
我正在尝试从 CSV 文件中获取行值,除了row[8]
. 但是同一行就像row[7]
我删除它之前的任何其他行一样。
comment = row[8]
IndexError: list index out of range
这是示例 CSV:
190,3391d5ae,,Host-1,FuelNode-1,"http,tcp-8000",False,,created on - 6/10/14
192,25dbbf4c,sam,"vlan85,vlan86","Srv1,Srv2",dhcp-relay,False,25-10-2018,
请注意,很少有字段没有值或空白。
这是我写的代码。
outFiles = os.listdir('datastore/csv_out_files')
ext = "*.csv"
for csvoutfile in outFiles:
if fnmatch.fnmatch(csvoutfile, ext):
with open('datastore/csv_out_files/'+ csvoutfile) as f:
rows = csv.reader(f, delimiter=',')
headers = next(rows)
for row in rows:
uid = row[1]
name = row[2]
source = row[3]
destination = row[4]
service = row[5]
enabled = row[6]
use_date = row[7]
comment = row[8]
if not use_date:
use_date = "Never Used"
print " UID:", (uid)
print " Name:", (name)
print " Source:", (source)
print " Destination:", (destination)
print " Service:", (service)
print " Enabled:", (enabled)
print " Last Used:", (use_date)
print " Additional Info:", (comment)
请帮助我,我无法弄清楚这一点。
解决方案
推荐阅读
- android - 如何键绑定我的音量增大/减小按钮以单击按钮?
- android - PendingIntent.getBroadcast 在奥利奥中不起作用
- type-conversion - 从 python 如何将 sys.settrace 回调中收到的帧对象传递给需要 void * 的 c++ 函数
- angularjs - 在子状态之间导航时清除父控制器数据:AngularJS
- python - NLTK 可用于停用词的语言
- windows - 如何在 powershell 中执行数学运算,或者更准确地说,从 .CSV 文件
- spring-integration - Spring Cloud Stream:如何为一组绑定指定单个消息处理程序?
- aurelia - 如何在 Aurelia-Dragula 中设置容器特定选项?
- symfony - 提交后如何仅获取更改的实体?
- c# - SQS 不能在 .Net 核心中仅发送 quations 消息