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
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?
Added June 2019: On the editor Run
menu, Run... Customized
opens a dialog with [X] Restart
. Uncheck that box and the restart is skipped.