How can I use Python to get the system hostname?
Question: 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.


Answer: Use [`socket`](http://docs.python.org/library/socket.html) and its
[`gethostname()`](http://docs.python.org/library/socket.html#socket.gethostname)
functionality. This will get the `hostname` of the computer where the Python
interpreter is running:

    
    
    import socket
    print(socket.gethostname())
    

