我已经完成了以下代码来从字符串中提取时间值。我想把每个时间值存储在不同的变量中。但它给出了错误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()
timeVar
是空列表,应使用append
而不是索引:相关问题 更多 >
编程相关推荐