Sublime Text 3環境SublimeREPLプラグインを使用してPythonファイルを実行


Sublime Text 3は軽便なIDEソフトで、Pythonが開発した利器に適しており、Pycharmの専門的な対口には及ばないが、軽くて使いやすく、機能がそろっている.しかし、デフォルトのbuildシステムを使用して入力するスクリプト(コードにはinput()メソッドが含まれている)を実行する場合、デフォルトのbuildメソッドは使いにくく、この場合SublimeREPLプラグインを使用する必要があります.SublimeREPLプラグインのインストールと構成について説明します.
  • Package Controlを使用してSublimeREPLプラグインをインストールできます.https://blog.csdn.net/lylfv/article/details/81452582
  • SublimeREPLプラグインを使用してpythonファイルTools->SublimeREPL->Python->Python-RUN current file
  • を実行
  • 試験コード(Python 3.6.1試験に合格)
  • def multi(x):
    	return x ** 3
    
    if __name__ == '__main__':
    	var = int(input('Please input a number: '))
    	print(multi(var))
    
    最適化:上記ステップ2の代わりにF 5キーを使用
    Sublime Text 3->Preferences->Key Bindings次の内容を入力して保存します.
    [ 
       	{
         
        "keys":["f5"],
        "caption": "SublimeREPL: Python - RUN current file",
        "command": "run_existing_window_command", "args": {"id": "repl_python_run",
        "file": "config/Python/Main.sublime-menu"}
         
        }
    ]
    
    付録:SublimeREPL構成Python 3使用
  • Preferences-> Browse Packages
  • SublimeREPL->configフォルダ
  • を開く
  • Python 3フォルダを新規作成し、次のファイル(Pythonフォルダ参照)Default.sublime-commands Main.sublime-menu
  • を追加します.
  • Default.sublime-commandsを修正します.内容は以下の通りです.
  • [
        {
            "caption": "SublimeREPL: Python3",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python3",
                "file": "config/Python3/Main.sublime-menu"
            }
        },
        {
            "caption": "SublimeREPL: Python - PDB current file",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_pdb",
                "file": "config/Python3/Main.sublime-menu"
            }
        },
        {
            "caption": "SublimeREPL: Python3 - RUN current file",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python3_run",
                "file": "config/Python3/Main.sublime-menu"
            }
        },
        {
            "command": "python_virtualenv_repl",
            "caption": "SublimeREPL: Python - virtualenv"
        },
        {
            "caption": "SublimeREPL: Python - IPython",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_ipython",
                "file": "config/Python3/Main.sublime-menu"
            }
        }
    ]
    
    
    5.  Main.sublime-menu,    :
    
    [
         {
            "id": "tools",
            "children":
            [{
                "caption": "SublimeREPL",
                "mnemonic": "R",
                "id": "SublimeREPL",
                "children":
                [
                    {"caption": "Python3",
                    "id": "Python3",
    
                     "children":[
                        {"command": "repl_open",
                         "caption": "Python3",
                         "id": "repl_python3",
                         "mnemonic": "P",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["python3", "-i", "-u"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python3/Python.tmLanguage",
                            "external_id": "python3",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
                        {"command": "python_virtualenv_repl",
                         "id": "python_virtualenv_repl",
                         "caption": "Python - virtualenv"},
                        {"command": "repl_open",
                         "caption": "Python - PDB current file",
                         "id": "repl_python_pdb",
                         "mnemonic": "D",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["python3", "-i", "-u", "-m", "pdb", "$file_basename"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python3/Python.tmLanguage",
                            "external_id": "python3",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
                        {"command": "repl_open",
                         "caption": "Python - RUN current file",
                         "id": "repl_python_run",
                         "mnemonic": "R",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["python3", "-u", "$file_basename"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python3/Python.tmLanguage",
                            "external_id": "python3",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
                        {"command": "repl_open",
                         "caption": "Python - IPython",
                         "id": "repl_python_ipython",
                         "mnemonic": "I",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "autocomplete_server": true,
                            "cmd": {
                                "osx": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                                "linux": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                                "windows": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
                            },
                            "cwd": "$file_path",
                            "syntax": "Packages/Python3/Python.tmLanguage",
                            "external_id": "python3",
                            "extend_env": {
                                "PYTHONIOENCODING": "utf-8",
                                "SUBLIMEREPL_EDITOR": "$editor"
                            }
                        }
                        }
                    ]}
                ]
            }]
        }
    ]