title: How do I catch an exception for a module that I've not fully imported?
body: <p>Normally, if I imported <code>socket</code>, I would be able to easily catch exceptions:</p>
  
  <pre><code>&gt;&gt;&gt; import socket
  &gt;&gt;&gt; try:
  ...     socket.gethostbyname('hello')
  ... except socket.gaierror:
  ...     print('oops')
  ...
  oops
  </code></pre>
  
  <p>But if I just import <code>socket.gethostbyname</code>, it won't work:</p>
  
  <pre><code>&gt;&gt;&gt; from socket import gethostbyname
  &gt;&gt;&gt; try:
  ...     gethostbyname('hello')
  ... except socket.gaierror:
  ...     print('oops')
  ...
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 3, in &lt;module&gt;
  NameError: name 'socket' is not defined
  </code></pre>
  
  <p>I also get a <code>NameError</code> if I try to catch <code>gaierror</code>.</p>
  
  <p>Is there any workaround for this? Is it not possible to catch an exception with a string (eg. <code>except 'socket.gaierror':</code>)?</p>