How to prevent python IDLE from restarting when running new script

前端 未结 2 664
一生所求
一生所求 2021-01-07 07:12

I use Python 3.6.1 IDLE. I\'d like to be able to run a sequence of scripts while maintaining the local environment (variables etc.) just as if I had entered all the commands

相关标签:
2条回答
  • 2021-01-07 07:34

    What about writing a master script that makes calls to execfile("other_script.py") (in Python 2) or exec(open("other_script.py").read()) (Python 3)? Then just run the master script in IDLE. You will probably need shebang lines and (possibly) appropriate execute permissions for each script.

    See this thread as I derived my answer from some stuff discussed there.

    Another option would be to automate your "typing things into the shell" with a shell script (bash, batch, sh, whatever shell you are using on your system).

    Realistically though, like others have said, it doesn't really seem like there is much benefit in modularizing this task by splitting it up into separate files. Why not just create a Python program that has all the functions you need, and then calls them as appropriate?

    0 讨论(0)
  • 2021-01-07 07:37

    Added June 2019: On the editor Run menu, Run... Customized opens a dialog with [X] Restart. Uncheck that box and the restart is skipped.

    0 讨论(0)
提交回复
热议问题