我的csv文件中的每一行都有如下字符串。如果搜索字符串的第一个单词,则必须打印从该单词开始的相应字符串
EQPHHC_10 | 16912 | 0 | 0 | 0 | 53040 | 0 | 544 | 0 | 140643 | 0 | Any message
我试过这个密码。如果我的搜索词是“EQPHHC\u10”,那么它必须打印从EQPHHC\u10开始的整个字符串
所需o/p-
EQPHHC_10 | 16912 | 0 | 0 | 0 | 53040 | 0 | 544 | 0 | 140643 | 0 | Any message
def find_index(input):
o = open('PROCESS.csv', 'r')
myData = csv.reader(o)
index = 0
for row in myData:
if row[0] == input:
return index
else : index+=1
Row_num = find_index('EQPHHC_10')
print Row_num
试试这个:
你很接近。您可以使用
enumerate
来查找索引例如:
你只需要读取文件和其中的行。找到索引,打印剩余的字符串
相关问题 更多 >
编程相关推荐