In the file mylibrary.py
I have the function
def myfunc(a,b):
return a+b
and in a Jupyter notebook I run
import mylibrary
mylibrary.myfunc(1,2)
and the output is 3
as expected.
However, when I update the the file mylibrary.py
so that its contents are
def myfunc(a):
return a+1
and run in Jupyter
import mylibrary
mylibrary.myfunc(1,2)
the output is an error:
TypeError: myfunc() missing 1 required positional argument: 'b'
Apparently Jupyter is still using the old version of mylibrary.py
. The error persists if I delete the cache created for mylibrary.py
after I try to import it.
Why is this happening, and how can I correct it? (An obvious workaround would be to define myfunc
in the Jupyter notebook instead of having it separate, which for now I will do. However, that works around the problem instead of actually fixing it, so that I still don't understand what went wrong and I may fall into a pitfall later as a result. Therefore, I think it's worthwhile to figure out what is going wrong.)