I want to use Sublime Text to write python scripts, but run them in IDLE.
So far I've created a build system like this:
{
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.8/bin/idle3", "-r", "$file"],
"file_regex": "*.py",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
This successfully runs the script in an IDLE shell. But when I run the script again, it closes the shell windows and reopens it.
I want to run the script in the same window as the first. It should only create a new window if there isn't already a shell open. This is the same way it works if you were to use the IDLE script writing window and run it there; it doesn't close and reopen the window.
I'm using a Mac by the way.
The IDLE Docs have this section on command line usage but I can't see anywhere about how I can do what I want. It just says "-r" is run. There is no run in an already opened shell.
Could anyone nudge me in the right direction for how I can do this please?
CodePudding user response:
You cannot currently do what you want. SublimeText asks macOS to start IDLE in python after putting the command-line arguments ('-r' and filename) jin sys.args. When IDLE starts, it reads sys.args. After that, there is no way for SublimeText to talk to IDLe.
What I could and might someday do is to add an option in IDLE to re-run the '-r' file, if any, when restarting the Shell with Shell=>Restart on the menu. You could then save in SublimeText and rerun in IDLE. Would that be better than the current situation?