title: Is it pythonic to import inside functions?
body: <p><a href="http://www.python.org/dev/peps/pep-0008/" rel="noreferrer">PEP 8</a> says:</p>
  
  <blockquote>
    <ul>
    <li>Imports are always put at the top of the file, just after any module
    comments and docstrings, and before module globals and constants.</li>
    </ul>
  </blockquote>
  
  <p>On occation, I violate PEP 8. Some times I import stuff inside functions. As a general rule, I do this if there is an import that is only used within a single function.</p>
  
  <p>Any opinions?</p>
  
  <p><strong>EDIT (the reason I feel importing in functions can be a good idea):</strong></p>
  
  <p>Main reason: It can make the code clearer.</p>
  
  <ul>
  <li>When looking at the code of a function I might ask myself: "What is function/class xxx?" (xxx being used inside the function). If I have all my imports at the top of the module, I have to go look there to determine what xxx is. This is more of an issue when using <code>from m import xxx</code>. Seeing <code>m.xxx</code> in the function probably tells me more. Depending on what <code>m</code> is: Is it a well-known top-level module/package (<code>import m</code>)? Or is it a sub-module/package (<code>from a.b.c import m</code>)?</li>
  <li>In some cases having that extra information ("What is xxx?") close to where xxx is used can make the function easier to understand.</li>
  </ul>