python - What is the correct way of getting a base (or short?) hostname? -


is there simpler/better or more pythonic way of getting base hostname?

base_hostname = socket.gethostname().split(".")[0] 

as example, how localhost below:

>>> socket.gethostname() 'localhost.localdomain' >>> socket.getfqdn() 'localhost.localdomain' >>> socket.gethostname().split('.')[0] 'localhost' 

i asking because suspect there similar os.path's abspath, basename, join, split, splitext, etc functions manipulate hostnames, haven't found yet.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -