ファイルを読み取るプログラムを作成しています。ファイルの最初の行が空白でない場合は、次の4行を読み取ります。これらの行で計算が実行され、次の行が読み取られます。その行が空でない場合、続行されます。ただし、次のエラーが発生します。
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())


with open(file_to_read, 'r') as infile:そこでの使用を検討してください。