0

put returns between paragraphs

► for linebreak add 2 spaces at end

italic or bold

► indent code by 4 spaces

► backtick escapes like _so_

► quote by placing > at start of line

► to make links (use https whenever possible) https://example.com

  • 1
    You must pass an argument to that script. It still won't work as `m` is not defined though. Also there is nothing in the code that uses the argument passed, so I'm not sure if you are posting the actual script or some hypothetical pseudo-code. – Selcuk Sep 14 '20 at 04:56
  • Why does the error in the headline differ from the one in the text and the code? – Klaus D. Sep 14 '20 at 04:58

1 Answers1

3

sys.argv is a list containing the program as invoked, and the arguments passed to it.

You've invoked the program as python3 proj.py, which means that sys.argv == ['proj.py'].

You then asked the program to access the second element of sys.argv via sys.argv[1]. There is no second element, so this fails with the given error.

Had you invoked the program as python3 proj.py foo, then sys.argv == ['main.py', 'foo'] and sys.argv[1] == 'foo'.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173