制作交互式和可重用的 Sublime Python 控制台的步骤:
1) 安装 SublimeREPL 插件:
在顶栏>“工具”>“命令面板”>“包控制:安装包”
搜索:“SublimeREPL”并安装
2)创建构建系统:
在顶部栏中 >“工具”>“构建系统”>“新构建系统”
将文件的所有内容替换为:
{
"target": "run_existing_window_command",
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
在默认的“用户”文件夹中将文件另存为“PythonRepl.sublime-build”。
3) 使控制台交互和可重用的设置:
|=> 转到“首选项”>“浏览包”
|=> 转到文件夹:SublimeRepl
|=> 编辑:sublimerepl.py
Replace : if view.id() == view_id
With : if view.name() == view_id:
|=> 转到文件夹:SublimeRepl/config/Python
|=> 编辑:Main.sublime-menu
|=> Under "caption": "Python - RUN current file"
|=> Append : "-i", in "cmd" as :
"cmd": ["python", "-u", "$file_basename"],
"cmd": ["python", "-i", "-u", "$file_basename"],
|=> Add : Before "external_id": "python"
"view_id": "*REPL* [python]",
|=> Full Code as shown below :
--------------------------------------------------
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"view_id": "*REPL* [python]",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
4)使用:
4.1) 在 Sublime Text 中打开要运行的 Python 文件。
4.2)在顶部栏>“工具”>“构建系统”>“PythonRepl”。
4.3) 构建 Python 文件,方法是选择 In Top Bar > "Tools" > "Build"
或
使用构建快捷方式(Windows 为 Ctrl+B,Mac 为 ⌘ Command+B)