title: How to get fully qualified host name in Python?
body: <p>I am trying to get the hostname in Python. In linux, if I type <code>hostname</code> on the command prompt I get</p>
  
  <pre><code>root@phxdbx45:/home/david/zkpython# hostname
  phxdbx45
  </code></pre>
  
  <p>But if I type <code>hostname -f</code> then I get below full qualified hostname in ubuntu and that's what I need from Python as well.</p>
  
  <pre><code>root@phxdbx45:/home/david/zkpython# hostname -f
  phxdbx45.phx.host.com
  </code></pre>
  
  <p>I know in Python we can use below code but it does not give me fully qualified host name. It gives me the output of <code>hostname</code> as I mentioned above.</p>
  
  <pre><code>#!/usr/bin/python
  
  import socket
  
  hostname = socket.gethostname()
  print hostname
  </code></pre>
  
  <p>Is there any way to get fully qualified hostname in Python which is reliable and correct?</p>