How to import only in parts of the code? [Python]
<p>I use webbrowser only in one part of my code, and it seems waste to import it since the beginning of the script, is it a way to import it only at the part of the code I need to use it? Thanks!</p>

<p>Yes. You move the import statement from the top of the script to the point in your script where you want it. For example, you would move the below line from the top of your script to somewhere in the code.</p>

<pre><code>import your_library
</code></pre>

<p>Be warned though, if the import is in a function, every time you call that function it will import that library, which may add time to the overall running of the file.</p>

<p>Let me know if you meant a different question.</p>

python performance python-2.7 libraries