I'm quite confused about the proper implementation of command line arguments in the program. I have looked around and confused whether the loop is necessary or not, I am convinced that only two arguments have been given for this program. In the end, is this necessary for the loop in this situation? The main function contains the code:
def main (): Try: if len (sys.argv)> 1: filename = sys.argv [1] length = int (sys.argv [2]) except wordDict = readFile (filename) IOError: print ("Error: File not found.")
Thank you all for your input!
If you know how many arguments you want, then you do not need to use a loop.
I have seen that in your code you check the number of sys.argv greater than 1, then you have to check that it was first sys.argv (sys.argv [0]) as it 2 is the name script that you are running
If only one argument has been passed to your program, then it will currently be an index error.
Comments
Post a Comment