Python-ValueError:以10为底的int()的无效文字:''

发布于 2021-02-02 23:17:57

我正在创建一个读取文件的程序,如果文件的第一行不为空白,它将读取接下来的四行。在这些行上执行计算,然后读取下一行。如果该行不为空,则继续。但是,我收到此错误:

ValueError: invalid literal for int() with base 10: ''.

它正在读取第一行,但无法将其转换为整数。

我该怎么做才能解决此问题?

代码:

file_to_read = raw_input("Enter file name of tests (empty string to end program):")
try:
    infile = open(file_to_read, 'r')
    while file_to_read != " ":
        file_to_write = raw_input("Enter output file name (.csv will be appended to it):")
        file_to_write = file_to_write + ".csv"
        outfile = open(file_to_write, "w")
        readings = (infile.readline())
        print readings
        while readings != 0:
            global count
            readings = int(readings)
            minimum = (infile.readline())
            maximum = (infile.readline())
关注者
0
被浏览
87
1 个回答
  • 面试哥
    面试哥 2021-02-02
    为面试而生,有面试问题,就找面试哥。

    仅作记录:

    >>> int('55063.000000')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: '55063.000000'
    

    我在这里…

    >>> float('55063.000000')
    55063.0
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看