Put imports at the top? Or where they get used?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/477096/python-import-coding-style">Python import coding style</a>  </p>
</blockquote>



<p>When I write some code that requires an import, and the import is only introduced by the bit of code I'm currently writing, should I:</p>

<p>Stick the import at the top of the file where it is made clear that to make this module work it needs these imports, yet the import is detached from the usage and should the need be removed later the module may still import stuff it doesn't ever actually use, or</p>

<p>Keep the import with the code that uses it immediately thereafter so it is obvious what the import is used to do and whence it can be safely removed, but risk importing the same libs multiple times and make it hard to work out what libs are required to make the module work.</p>

<p>Best practice?</p>

<p>Put the import at the top? Or put it where it gets used?</p>
