How can I use Python to get the system hostname?
Both of these are pretty portable:
import platformplatform.node()import socketsocket.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.