Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow VS Code to take input from users?

Tags:

I have installed Visual Studio Code 1.23.1 and added extensions - Python, Code Runner.

With Code Runner, now I can see the Run Code symbol (triangle) and on highlighting it, I see the shortcut Ctrl + Alt + N. But when I try to use it to run the code that asks for user input, I can't find a way to provide the input. When I try to enter user input, I get error message "Cannot edit in read-only editor". I think this is because I am missing some configuration part for Code Runner like setting up PATH or some other Workspace settings.

Question: Please assist me in identifying what all configuration will I need to do and how?

I did select "Add Python 3.6 to PATH" while installing Python. I have attached screenshots for reference:

ExecutionError ExecutionError

Note: Even now when I right click and select "Run Python File in Terminal" for the same program, I can enter user input fine and get the expected output. ExecutionWorking

like image 392
300 Avatar asked Jun 04 '18 21:06

300


People also ask

How do I enable user input in VS Code?

Go to settings (ctrl+,) -> Search settings -> : Code-runner : Run in terminal - Check this and you will be able to run the code directly in the terminal which takes input. :) Save this answer. Show activity on this post.

Why does my VS Code not take input?

Your program is running in Output tab, therefore it is not possible to take input. Just enable Run in terminal in Visual Studio Code Settings.

How do you source in VS Code?

First, select DevTools > Settings > Experiments > Open source files in Visual Studio Code, and then re-start DevTools. With this experiment enabled, suppose that in Microsoft Edge, you go to a local server (such as http://localhost or http://127.0.0.1 ), or open a local file.

How do you collaborate using VS Code?

If you select Start Collaboration session from the Session Details menu, an invitation link to your session will automatically be copied to your clipboard. You can share this link with anyone you'd like to collaborate with, as long as they also have VS Code and the Live Share Extension Pack downloaded.


1 Answers

Here's another alternative answer, I think more accurate.
Add following settings to your vscode user settings file:

"code-runner.executorMap": {     "python": "$pythonPath -u $fullFileName", }, 

Check out this reference for some useful variables: Variables Reference

like image 58
Lukewcn Avatar answered Oct 02 '22 18:10

Lukewcn