0
我想总结变量l,而不是一个数字,我正在获取浮动列表。 这里是我的代码:在Python中如何总结浮点列表
import re
fname = raw_input("Enter file name: ")
hand = open(fname)
for line in hand:
line = line.rstrip()
if not line.startswith("X-DSPAM-Confidence:") : continue
for lines in line:
x = re.findall('^X\S*: ([0-9.]+)', line)
l = map(float, x)
print sum(l)
谢谢Stidgeon。 当我尝试代码时,我得到一个错误:TypeError:float()参数必须是一个字符串或数字 – Hanan
谢谢Stidgeon,伟大的作品 – Hanan