且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

float()的无效文字:0.000001,如何修复错误?

更新时间:2023-09-18 13:21:28

从您发布的内容来看,您不清楚要传递给float()的字符串是否存在某些细微的错误(因为它看起来完全合理).尝试添加调试打印语句:

From what you've posted, it's not clear whether there is something subtly wrong with the string you're trying to pass to float() (because it looks perfectly reasonable). Try adding a debug print statement:

print(repr(items[2]))
p_value = float(items[2])

然后,您可以准确确定 传递给float()的内容.调用repr()将使通常不可见的字符也可见.将结果添加到您的问题中,我们将能够进行进一步评论.

Then you can determine exactly what is being passed to float(). The call to repr() will make even normally invisible characters visible. Add the result to your question and we will be able to comment further.