简体   繁体   中英

Reload method of already existing object on console in Python

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM