Calling a function from a script, re-import all packages?
<p>Say I have some script, with a function <code>my_function</code>. Now, this function needs several packages. So, let's say the file looks like this:</p>

<pre><code>import package_A
import package_B

def my_function():
    do_something
</code></pre>

<p>Now, if I want to use this function somewhere else, I may say </p>

<pre><code>from my_file import my_function
my_function()
</code></pre>

<p>However, at this point, the call will halt with the error that package_A and package_B are not known. </p>

<p>How do I solve this? Do I have to make all the imports I do for <code>my_function</code> again in the script calling <code>my_function</code>? And if so, is there a way to automatically check and import all the imports in that file?</p>

<p>You can have several scripts calling each other can can import several packages in each script and it won't throw up an error until you have packages that are required for the functions in that script.</p>

<p><a href="http://stackoverflow.com/questions/15696461/import-python-script-into-another">Found this link which will answer your question better</a></p>

python import