In Python, how to get the hostname of the node?
In Python, you can get the hostname by the
library function in the
socket.gethostname()socket
module:
import socket
hostname = socket.gethostname()
Example:
$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostname()
'host001'