Pycharm console caching?

已回答

Hi - new to Python and Pycharm, so hope this is not too stupid of a question. I did spend some time trying to find an existing answer first!

 

In console -

1) I import a file (MyFile.py)

2) i instantiate a class from that file ... o=MyFile.MyClass()

3. All is good - can see attributes and run methods via o.whatever

4) Now i want to change something about the class - maybe an attribute initial value or what a method returns

5) I del o and del MyFile - i'm hoping /assuming that gets them out of memory/scope?

6) i make the change I want in the py file, and save

7) in console, import Myfile again and reinstatiate via o= o=MyFile.MyClass()

8) o now seems to hold the PREVIOUS version of the class now w/o the changes i just made?

What am I missing?

THANKS!

 

0

Hi Ken, this is not a PyCharm bug, in fact, Python console outside of PyCharm will give you the same result, correct way to reload the module is

import sys
del
sys.modules['MyFile']

or better

from importlib import reload
reload(MyFile)

Related question on StackOverflow: https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module

1
Avatar
Permanently deleted user

Thanks! I appreciate it!

0
Avatar
Permanently deleted user

Related - sort of - question ...

 

is there a quick, one line, way to essentially "clear everything I've added in my session out of memory? (leaving just the base stuff? In other words - setting it to a "fresh" state as if I had just opened pycharm and a new console?

Thanks!

0

请先登录再写评论。