Context:
I had been developing some project in python and had decided to move functions which used to separate files (functions.py). I had created and imported it in my notebook. After that I added some functions to the file.
After I had reloaded the cell with import I tried to run the cell with code, which uses composition from functions.py, and found out that it wasn’t imported.
I restarted the kernel and cell comiled.
Why didn’t notebook import my file wholly? Maybe because it caсhed first time and did not read the actual file again?
Code of functions.py:
def composition(f:callable, g:callable) -> callable:
def cmp(x):
return f(g(x))
return cmp
Code of project.ipynb:
Cell 1:
from functions import *
Cell2:
s = composition(lambda x: x**2, lambda x: x**4)
Error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_21766/3463491651.py in <module>
----> 1 s = composition(lambda x: x**2, lambda x: x**4)
NameError: name 'composition' is not defined
I use python 3.8.10 64-bit and editor is Visual Studio Code 1.61.2