Trying to do some basic error checking. Only started with Python a few days ago. I’m confused why the following code does not work. No matter whether I start the program with 3 or 4 arguments, I always get the error message, and I don’t understand why that happens. Similar code has worked for me before in other programs. Please enlighten me what is happening here.
–code starts–
some basic error checking
no_third_file = False
try:
outputfile = sys.argv[1]
inputfile1 = sys.argv[2]
inputfile2 = sys.argv[3]
inputfile3 = sys.argv[4]
except:
outputfile = sys.argv[1]
inputfile1 = sys.argv[2]
inputfile2 = sys.argv[3]
no_third_file = True
finally:
print(‘Not enough command line arguments found. Usage:’)
print(sys.argv[0], ‘outputfile inputfile1 inputfile2 inputfile3’)
print(‘Total output size is expected to be about two thirds of total input size’)
print(‘If only two input files are available, the third can be omitted’)
print(‘In that case, xor will be used to reconstruct the third file’)
quit()