0

I want to ask that how can we make our VS Code workspace such that we can preset all the input we want to give to our python program at once and it uses that data when it runs in the terminal.

Like if I am working on a program and it takes multiple lines of input to reach to a part I am testing, I don't want to sit there and enter all the input data required by myself each time I change something and want to test my program and want that I can fix the inputs the program will take once I run the program.

For reference, I want to create my VS Code like the Code Chef Practice Workspace where we can write the program and preset the inputs in a box and each time we run the program, It automatically uses the input data and we don't have to type it in.

So If anyone knows any extension or method to make VS Code work like that, please help me by providing the solutions.

3 Answers3

0

Put the data into file and use the Terminal: YourProgram.py < input.txt

Gustasvs
  • 41
  • 1
  • 6
  • Ok thats one way to do it but isn't there also a way to change the VS Code such that there is a GUI Box where you can just type the data to do the same. Because creating a input file for each and every code will also be a pain. And if you run your program using the run button then you don't get a chance to edit the run command entered into the terminal – Vikas Mittal Jul 20 '22 at 20:22
  • This link looks promising - https://calvh.medium.com/how-to-pass-input-files-to-stdin-in-vscode-cb31cd7740b8. – Gustasvs Jul 20 '22 at 20:30
  • If being honest, I know nothing about handling .json files and have never used the settings.json file in VS Code to change anything and the writer of the blog has also not specified as to how to do the whole process, so I am still looking for a process that I can follow. – Vikas Mittal Jul 20 '22 at 20:41
  • Good luck finding something! I don't think I can be of any help here because as a competitive programmer I have used terminal/file inputs all my life. Let's just wait for someone else to answer! – Gustasvs Jul 20 '22 at 20:48
0

You can do that in VSCode by editing the launch.json configuration file for python. https://go.microsoft.com/fwlink/?linkid=830387

naveenkrdy
  • 24
  • 3
0

args configuration in launch.json:

Specifies arguments to pass to the Python program. Each element of the argument string that's separated by a space should be contained within quotes, for example:

"args": ["--quiet", "--norepeat", "--port", "1593"],
JialeDu
  • 6,021
  • 2
  • 5
  • 24