“list index out of range” when using sys.argv[1]

With this Python:

import sys

print(sys.argv)

And invoked with this command:

>python q15121717.py 127.0.0.1

I get this output:

['q15121717.py', '127.0.0.1']

I think you are not passing a argument to your Python script

Now you can change your code slightly to take a server form the command line or prompt for a server when none is passed. In this case you would look at something like this:

if len(sys.argv) > 1:
    print(sys.argv[1])
else:
    print(input("Enter address:"))

Leave a Comment