如何转换这种类型的数字: 2.000000000000000000e + 00 到int(值2)?
谢谢!
def read_labels_from_file(file_name):
labels_file = open(file_name, "r")
labels = []
for line in labels_file:
line_sepetated = line.split("\n")
labels.append(int(line_sepetated[0]))
return labels
我希望将整数2附加到标签上,但是得到: ValueError:以10为底的int()的无效文字:'2.000000000000000000e + 00'
答案 0 :(得分:0)
2.000000000000000000e+00
是有效的浮点文字,因此您可以先将其转换为float
,然后再将其转换为int
:
labels.append(int(float(line_sepetated[0])))