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

前端 未结 18 2114
甜味超标
甜味超标 2020-11-22 02:06

I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then t

18条回答
  •  一个人的身影
    2020-11-22 03:04

    I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then the next line is read.

    Something like this should work:

    for line in infile:
        next_lines = []
        if line.strip():
            for i in xrange(4):
                try:
                    next_lines.append(infile.next())
                except StopIteration:
                    break
        # Do your calculation with "4 lines" here
    

提交回复
热议问题