在lis中存储多个变量时,列表分配索引超出范围

2024-09-30 02:23:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经完成了以下代码来从字符串中提取时间值。我想把每个时间值存储在不同的变量中。但它给出了错误list assignment index out of range

stringToMatch4 = '=========*******Time'
timeVar = []
matchedLine4 = []   
with open('un_AO', 'r') as file:
    if stringToMatch4 in line:   
      matchedLine4.append(line)

list4Len = len(matchedLine4)

   for x in range(0,list4Len):
     timeVar[x] = (matchedLine4[x]).replace(stringToMatch4,'').rstrip()

Tags: 字符串代码inindex错误line时间range

热门问题