0

In the Python console (Eclipse, Pydev) I execute some data loading. Afterwards I change some source code of a method of the object and would like to include the new functionality in the data objects. The data loading is quite slow so I do not want to restart the whole script.

Is there a magic way to update the object methods with the new implementation that I edited in the source code?

How to reload the code of a method of class object in Python? says I cannot do this in a standard way.

So can you think of some way to simulate that functionality? Maybe reload the class definition and then recreate all data objects by examining their __dict__ or similar? Ideally this would be as automatic and comfortable as possible. What do I need to take into account?

1 Answer 1

1

Unfortunately, Python can't replace existing instances of objects out of the box. However, IPython implements this functionality as extension. You could use IPython as Python console or just re-implement this feature for your development environment.

See Autoreload of modules in IPython, and ipython docs.

Sign up to request clarification or add additional context in comments.

2 Comments

I see :) However, it would not reload class of objects that are already in memory?
It actually does reload classes which are already in memory. Try example of ipython autoreload using from previously mentioned SO question. For me it works also with with classes and objects.

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.