Run a module in IDLE (Python 3.4) without Restart

2019-06-09 01:14发布

It appears that, in the past, IDLE did not restart (clean the environment) when you ran a script (module). Today, however, this is the case. But for prototyping I would like the environment (assigned variables, imported modules, functions, ...) to survive running different modules (files).

Example: I am working on a function, let's call it f7(), that requires a certain environment. The environment is built in another script (file), say, env1.py. After env1.py has been run, I can built on all imported modules, defined functions and assigned variables, when working at the command line of IDLE. But I cannot run another file, where my f7() resides! I would have to redefine f7() at the interpreter's command line. Which I of course do not do, because f7() is very lengthy. The only thing that remains is to include f7() in env1.py. And restart it after every change to f7(). As a consequence, I have to wait each time until env1.py has finished. Which is a waste of time, because every time it runs, it does the same. I only change f7()...

Can I tell IDLE not to restart (clean environment) each time I run a module (file) in IDLE? If not, what alternatives to IDLE are capable of something like this?? It seems IDLE behaves the same on Windows, Ubuntu, Raspbian. I am using Python 3.X on each of these systems.

1条回答
迷人小祖宗
2楼-- · 2019-06-09 02:03

I am not aware that IDLE ever didn't restart when running a editor file, so that would have to have been several years ago. I will think about it as a new feature though.

In the meanwhile, you can do this for the specific scenario you gave. Load env1.py into an editor window and run it. When >>> appears, enter or paste the def statement for f7 and run it. (Paste after loading the file with f7 and copy.) Test by calling f7. To edit the definition of f7, recall it to the current >>> line. Either click on the previous definition and hit Enter or use the history keyboard shortcuts (for me on Windows, Alt-P for Previous, Alt-N for Next). In either case, edit and re-run. Do the same with test statements. I recall and edit statements routinely.

查看更多
登录 后发表回答