Sublime Forum

Py program not running after user input?

#1

Hello everyone,

Im starting with Python on Sublime and I was following a tutorial that makes the user input a greeting, such as “Hello”
greeting = input("write a greeting: ")
print(greeting)

When I build the program, “Write a greeting” appears and I type “Hi” but then nothing happens.
What should happen is that “Hi” should be printed.

What I am doing wrong?

0 Likes

User input
Running script within Sublime
#2

Running the builtin “Python” build script does not start an interactive python shell, therefore no keyboard input is handled. It just starts the script and prints the output to the build panel.

If you want to run python interactively the Terminus package might help you.

  1. Install Terminus
  2. Create a Terminus Python.sublime-build file with the following content
    {
        "target": "terminus_open",
        "selector": "source.python",
        "cmd": ["python", "-u", "$file"],
        "env": {"PYTHONIOENCODING": "utf-8"},
        "cwd": "${file_path:${folder}}",
    }

This will run python as interactive shell via Terminus and execute your script. If done, the session is closed.

4 Likes

#3

Alright thanks! Will try this out.

0 Likes

#4

Hello,
I installed Terminus and it works fine, but currently I have to save my python file, go to another tab with Terminus and run the file there.
Is there a way to automatically run Terminus on a python file when I hit ctrl+B on my keyboard? I want to automatically run Terminus instead of the build panel.
Thank you!

0 Likes

#5
1 Like