Issue with Sublime Text 3's build system - can't get input from running program

后端 未结 2 1514
北恋
北恋 2020-11-22 09:38

I\'m trying to get Sublime Text 3 (build 3049, if that matters) to run a Python script. A simple two liner

var = raw_input(\"Enter something: \")
print \"You         


        
相关标签:
2条回答
  • 2020-11-22 09:55

    Sublime Text on its own cannot handle input via raw_input() or input(). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. The easiest short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL (you'll need to start one first).

    If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:

    {
        "cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
        "selector": "source.python",
        "shell": true,
        "working_dir": "$file_dir"
    }
    

    changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.

    Please note that this build system is Windows-specific.

    0 讨论(0)
  • 2020-11-22 10:15

    Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL. Follow this:

    1. open Sublime Text >> CTRL + P

    2. CTRL + P will open the Package control

    3. Click on Package Control: Install package
    4. Wait for a sec to pop up a search bar.
    5. Type SublimeREPL and Click it. It'll get installed in a few secs.

    Then follow the following steps to run your program;

    1. Tools >> SublimeREPL >> Python >> Python run Current File

    It'll open a new window, where you can give your input and get the output.

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