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

I am writing a simple client and Python server that works fine by passing the server address in my code, however I want the user to be able to enter the server address, and also throw and fail if this is not true. When I have the code below, I get an error message from the terminal "index index out of range".

server = (sys.argv[1])
serverAdd = (server, '65652') # server address and port number

Can someone help me with this please.

When I run my client program in python, I want to be able to enter the address for connection and storage on the server. I run the program directly from the command line by typing programname.py. The server is already working, listening to incoming connections.

+5
source share
1

Python:

import sys

print(sys.argv)

:

>python q15121717.py 127.0.0.1

:

['q15121717.py', '127.0.0.1']

, Python script

, , . - :

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

All Articles