遍历并提取子字符串

时间:2018-08-10 08:08:54

标签: python list index-error

为什么我的列表索引超出范围?

ip_list = []
path = r'''mail.log'''
with open(path, 'r') as log:
  for line in log:
      if "SASL PLAIN authentication failed: authentication failure" in line:
          ip_address = line.split("warning: unknown[")[1].split("]")[0]
          ip_list.append(ip_address)

输出:

...
ip_address = line.split("warning: unknown[")[1].split("]")[0]
IndexError: list index out of range

0 个答案:

没有答案