How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook? : <p>I am working on a Python Notebook and I would like that <strong>large input code [input]</strong> <strong>pack into a [* .PY] files and call this files from the notebook</strong>. </p>

<p>The action of running a [<em>.PY] file from the Notebook is known to me and the command varies between Linux or Windows. <strong>But when I do this action and execute the [.PY] file from the notebook, it does not recognize any existing library or variable loaded in the notebook (it's like the [</em>.PY] file start from zero...)</strong>. </p>

<p>Is there any way to fix this?</p>

<p>A possible simplified example of the problem would be the following:</p>

<pre><code>In[1]:
import numpy as np
import matplotlib.pyplot as plt

In[2]:
def f(x):
    return np.exp(-x ** 2)

In[3]:
x = np.linspace(-1, 3, 100)

In[4]:
%run script.py
</code></pre>

<p>Where "<strong>script.py</strong>" has the following content:</p>

<pre><code>plt.plot(x, f(x))
plt.xlabel("Eje $x$",fontsize=16)
plt.ylabel("$f(x)$",fontsize=16)
plt.title("Funcion $f(x)$")
</code></pre>

<ul>
<li>In the real problem, the file [* .PY] does not have 4 lines of code, it has enough more.</li>
</ul>
