I'm writing a chat program for a local network. I would like be able to identify computers and get the user-set computer name with Python.
import socket print(socket.gethostname())
Both of these are pretty portable:
import platform platform.node() import socket socket.gethostname()
Any solutions using the
HOSTNAME environment variables are not portable. Even if it works on your system when you run it, it may not work when run in special environments such as cron.