[Tutor] Python -> uname -n

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Sep 14 00:19:36 CEST 2004

On Mon, 13 Sep 2004, Tim Johnson wrote:

> > How may I obtain the network node hostname with python?
> >
> > On linux, it would be the value returned by 'uname -n'
> Found it all by my lonesome, under Python Library Reference, the
> 'commands' module.
> commands.getstatusoutput('uname -n') returns a 2 - member tuple with
> status code as the first item and response string as second item.

Hi Tim,

You might be able to get it with 'socket.gethostname()' as well:

>>> import socket
>>> socket.gethostname()



for more details on socket.gethostname().

Good luck!

More information about the Tutor mailing list