Get the hostname

Gerhard Häring gh at ghaering.de
Wed Aug 6 07:44:20 EDT 2003


Lukas Schnieper wrote:
> Hi
> How can i get the hostname of my Linux PC?
> I tried os.system('hostname') but i cant save the hostname in a variable 
>  like hostname = os.system('hostname')

Check out the functions gethostname() and getfqdn() in the socket module.

To read the output of an external system command, you can use the 
commands module.

-- Gerhard





More information about the Python-list mailing list