0

I'm working with Jupyter for compiling code. I have created a set of different .py script creating the class for each script. Basically, I have the script my_class.py which includes

  def functional_feed(self):
    a=5
    return a

Now in Jupyter I'm using:

from f.rel import my_class
gre= my_class.functional_feed()

and it works with 5. But if I change something in my_class and within functional_feed, for instance, the def becomes:

 def functional_feed(self):
  a=11
  return a

and try to compile again within jupiter, all the changes have not effect and it returns 5.

Why?

thank you in advance

1
  • I think that you must restart the kernel of the notebook where you import the class. Commented Nov 13, 2020 at 16:43

1 Answer 1

1

Python caches imports by default, so you have to reload the import:

import f.rel
import importlib
# clear the import cache
importlib.reload(f.rel)
# now you can import my_class and it'll be updated
from f.rel import my_class
Sign up to request clarification or add additional context in comments.

2 Comments

First of all, thank you for your reply. I don't know why, but it doesn't reload the script. If I delete the content from my_class.py, and reload as you suggested it returns always 5.
could it happen due to the colab environment?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.