how to get hostname in python
Saturday, May 17th, 2008import socket
host = socket.gethostname()
print host
import socket
host = socket.gethostname()
print host
Sometimes we want to iterate over a dictionary in sorted order of value. Here is the code:
d = {”a”:1, “b”:5, “c”:2, “be”:30}
for k in sorted(d.keys(), lambda x,y:d[x]-d[y]):
print “%s=%s” % (k, d[k])
# output is:
a=1
c=2
b=5
be=30