我编写了一个脚本,该脚本允许我循环提取所有浮点数并将它们放在列表中,然后显示此列表以及所有提取的浮点数,除了在我的脚本中只取每个列表的最后一个数字考虑到这一点,而我希望显示所有数字。怎么做?
有我的代码:
final_result = []
result = []
k = listFps
k = 0
while k < len(listFps):
with open(listFps[k], 'r') as f:
#
statList = f.readlines()
statList = [x.strip() for x in statList]
for line in statList:
if (re.search("=", str(line))):
if (re.search('#IND', str(line))):
print("ok")
else:
result =re.findall("=\s*?(\d+\.\d+|\d+)", str(line))
print (" ca c result " ,result)
numberList = [float(q) for q in result]
print("ca c number list :",numberList)
k+=1
它仅向我显示列表中的最后一个元素,如下所示:
[59.889]
[60.874]
等。 但是我实际上想要一个包含所有元素的列表:
[59.889,60.874....]
请帮助我,让我坚持太久。.
答案 0 :(得分:0)
代替
result = re.findall….
使用
result += re.findall…