python中横向制表符_如何检查python中包含制表符的列表?

Connecting to the ControlService endpoint

Found 3 rows.

Requests List:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Client ID | Client Type | Service Type | Status | Trust Domain | Data Instance Name | Data Version | Creation Time | Last Update | Scheduled Time |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

REFRESH_ROUTINGTIER_ARTIFACTS_1465901168866 | ROUTINGTIER_ARTIFACTS | SYSTEM | COMPLETED | RRA Bulk Client | soa_server1 | 18.2.2.0.0 | 2016-06-14 03:49:55 -07:00 | 2016-06-14 03:49:57 -07:00 | --- |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

500333443 | CREATE | [FA_GSI] | COMPLETED | holder | soa_server1 | 18.3.2.0.0 | 2018-08-07 11:59:57 -07:00 | 2018-08-07 12:04:37 -07:00 | --- |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

500333446 | CREATE | [FA_GSI] | COMPLETED | holder-test | soa_server1 | 18.3.2.0.0 | 2018-08-07 12:04:48 -07:00 | 2018-08-07 12:08:52 -07:00 | --- |

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

现在我要分析上面的文件和最后一行的额外值。我想在最后一行增加“Client ID”和“Trust Domain”列的值,即:

Client ID: 500333446

Trust Domain: holder-test

我得到了下面的python脚本,但是由于csv文件末尾的新行而失败了?如果我的csv文件没有任何新行,那么它可以正常工作。

import csv

lines_to_skip = 4

with open('data.csv', 'r') as f:

reader = csv.reader(f, delimiter='|')

for i in range(lines_to_skip):

next(reader)

data = []

for line in reader:

if line[0].find("---") != 0:

print line

data.append(line)

print("{}={}".format(data[-1][0].replace(" ",""),data[-1][4].replace(" ","")))

如果csv文件的末尾有一些新行,则在if block line处会出现此错误:

Traceback (most recent call last):

File "test.py", line 11, in

if line[0].find("---") != 0:

IndexError: list index out of range

这是最后打印出来的行:

[' \t\t']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值