我尝试用以下python代码将文件中的一些浮动值填充到元组中:
with open(filename, 'r') as file:
i=0
lines = file.readlines()
for line in lines:
if (line != None) and (i != 0) and (i != 1): #ignore first 2 lines
splitted = line.split(";")
s = splitted[3].replace(",",".")
lp1.heating_list[i-2] = float(s)
i+=1
这些值来自.csv文件,其中的行如下所示:
MFH;0:15;0,007687511;0,013816233;0,023092447;
问题是我得到:
lp1.heating_list[i-2] = float(s)
ValueError: could not convert string to float:
我不知道怎么了。请照亮我。你知道吗
这可能意味着什么是说。变量
s
是一个字符串,它不是浮点数。 您可以尝试添加此代码段以打印/查找有问题的字符串。你知道吗另见类似问题:https://stackoverflow.com/a/8420179/4295853
相关问题 更多 >
编程相关推荐