0

I am having an issue with the following section of Python code:

def main():
file_name = sys.argv[1]
file = open(file_name, 'r')
l = []
for line in file:
    if (len(l) == 4):
        res = valid_data(l)
        if (res == False):
            print("The Data is InValid")
        else:
            print_data(l)
        l = []
    else:
        l.append(line.strip())
if (l != []):
    res = valid_data(l)
    if (res == False):
        print("The Data is InValid")
    else:
        print_data(l)
main()

Specifically, the error is as follows:

 Traceback (most recent call last):


File "C:\Users\Desktop\44.py", line 194, in <module>
main()



 File "C:\Users\Desktop\44.py", line 173, in main
information = sys.argv[1]
IndexError: list index out of range

The sys.argv might require an argument at the command line when running the script, but I'm not sure what the issue might be!

halfer
  • 19,471
  • 17
  • 87
  • 173
Roy
  • 1
  • 2

1 Answers1

-1

sys.argv[1] is the first command line argument. Call the script like

python3 myscript.py myargument
jmd_dk
  • 10,613
  • 6
  • 57
  • 84