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?

Community
  • 1
  • 1
Gere
  • 12,075
  • 18
  • 62
  • 94

1 Answers1

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.

Community
  • 1
  • 1
Aliaksei Ramanau
  • 909
  • 1
  • 9
  • 16
  • I see :) However, it would not reload class of objects that are already in memory? – Gere Oct 27 '12 at 20:34
  • 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. – Aliaksei Ramanau Nov 01 '12 at 10:36