Reputation: 665
I think this is a really silly / dumb question, but I am using PyCharm and constantly adding methods to a class or changing the body of the methods. When I test the class by importing the .py file and initiating the class object, it doesnt seem to recognize the changes to the class.
Is there some button I need to hit to make sure that the class code is changed.
The only thing that seems to work for me is to restart PyCharm.
Upvotes: 3
Views: 2059
Reputation: 6015
There many variations of the issue you have stated. One issue I have faced is having two classes in the module - one containing another's object.
e.g.
class y:
@classmethod
def f1():
print('old')
class x:
def __init__(self):
self.ref_cls = y()
def test():
self.ref_cls.f1() # <-- "line to change"
Now if I place a breakpoint over "line to change" and want to redef f1 to print 'new' instead of 'old', I open the evaluator and add following code:
class new: # <-- if you write 'y' instead of new it does not work
@classmethod
def f1():
print('new')
self.ref_cls = new
Evaluate this and then step over to confirm in the console. This works for static methods and object methods as well.
Hope this helps.
Upvotes: 0
Reputation: 43447
When you import the class, it imports it as-is at the current time. If you make changes after that, you need to import it again. In this case, you should just be able to terminate the shell, and start it again.
This is not an error, or a bug.
Upvotes: 5