简体   繁体   中英

How to restart pydev interactive console after a code change?

I use Eclipse with pydev for python development. I would like to test my code using pydev's interactive python console. When I make a change in the code, interactive pydev console doesn't notice it, and i have to close the current pydev console and open a new one to reflect the changes. Is there an easier way to get the changes to current active console? maybe a restart button?

Ok, I found a cool way to do it. Whenever you launch a new Pydev console; choose the option of Console for currently active editor .

Within the python prompt in the interactive console type the following

execfile('<full_path_to_your_python_script>')

Now you can experiment with the code in your script.

If you change something within the file (such as a method or class definition), then again within the same Pydev console execute the execfile statement. This will re-load the currently active editor file and you will now have access the modified code.

Note: I guess this behavior is because, the importing activity in Python are idempotent - ie a module can imported only once. After it has been imported, any subsequent imports for the module will refer and return the previously imported module instance. The only way to get the latest definition of the module then is to use a reload('module_name') method. I guess this is what execfile does - it reloads the python module corresponding to the currently active editor file.

在编码窗口中进行ctrl + alt + 输入 (控制台是否打开),您将自动加载当前代码以供使用。

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