A while back I wrote a socket programmed chat in Python. This question isn't really about the program specifically, moreso on conventions of Python and my style of coding. I've only been using Python for a couple of months and any pointers would be appreciated.
Here's some code I'm curious about:
# in case of inappropriate arguments, remind user how to execute
if len(sys.argv) != 3:
print("\nExecute the script as below:")
print(" $ ./sock_client.py <IP Address> <Port>")
print("For example: `./sock_server.py 127.0.0.1 8008`.")
print("Additionally, ensure the socket server is live beforehand.\n")
sys.exit(1)
In all of my Python projects so far, which all are ran from a terminal, I have a block of code like this at the top to ensure number of arguments, and if not, remind the user on how to execute. I don't know if this is good convention or not.
def send_user(m, u):
"""
Sends a message to a single client.
Parameter:
m -- the message to send
u -- the client to send to
"""
for c in CLIENT_LIST:
# only specific client/user
if CLIENT_LIST[c] == u:
c.send(bytes(m, "utf8"))
Here's an example docstring. Were I to have a return statement, it would look more like this, though:
def function(param1, param2):
"""
What function does in a couple words.
More detail if needed.
Parameter:
param1 -- some parameter
param2 -- another parameter
Return:
-- some value
What is considered ideal convention for docstrings?
Here's the full repo: link.