How to get computer name
Tim Heaney
theaney at cablespeed.com
Sat Apr 29 12:57:47 EDT 2006
"pitarda" <pitarda at gmail.com> writes:
> How do I get the computer name in python?
You can use the os module to get it from your environment.
>>> import os
>>> os.getenv('HOSTNAME')
'calvin.watterson'
Depending on your operating system, the environment variable you need
might have a different name. For example, I think in Windows you
might try
>>> os.getenv('COMPUTERNAME')
You can see all of the environment variables currently available with
>>> os.environ
I hope this helps,
Tim
More information about the Python-list
mailing list