3

After I run my python code in the terminal, it displays a few paths in the 1st line and then the output of my code in the 2nd line. Can I hide the 1st line so I only see the output in the 2nd line?

C:\Users\Venyl\Desktop\VS CODE\Code 2020>C:/Users/Venyl/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/Venyl/Desktop/VS CODE/Code 2020/print('lol').py"
hello world
Venyl
  • 39
  • 1
  • 1
  • 2
  • Put the path to python in windows environement variables at the and of PATH – JB_DELR Sep 05 '20 at 21:41
  • 1
    The entire path of python.exe. Then you can call python from anywhere. – JB_DELR Sep 05 '20 at 22:02
  • https://imgur.com/a/MS7ZcH4 it just displays this now, it still shows the 1st line that is the path – Venyl Sep 05 '20 at 22:04
  • Now in vsCode go to python extension setting. You can find close to the end "Python: Python Path" to put python.exe, and maybe python.terminal.executeInFileDir – JB_DELR Sep 05 '20 at 22:20
  • https://imgur.com/a/QkPzDlN and now it just displays this lol – Venyl Sep 05 '20 at 22:25
  • I can't do better. To run a python script, you have to write: python.exe scriptName.py, it's the minimum. – JB_DELR Sep 05 '20 at 22:34
  • oh ok thanks anyways :) – Venyl Sep 05 '20 at 22:59
  • 1
    Does this answer your question? [How to hide file paths when running Python scripts in VS Code?](https://stackoverflow.com/questions/61176552/how-to-hide-file-paths-when-running-python-scripts-in-vs-code) – Gino Mempin Feb 21 '21 at 23:28
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Feb 22 '21 at 11:55

4 Answers4

3
  1. You could use the following settings in launch.json in the .vscode folder, and "console": sets the way the code debugging results are displayed.

"console": "internalConsole",

After setting it, the debugging result will be displayed in the "debug console" inside VSCode.

enter image description here

  1. We could also set it as:

"console": "externalTerminal",

and the debugging results will be displayed in the "cmd" window outside VSCode. It also only displays the debugging results:

enter image description here

  1. VSCode uses by default: "console": "integratedTerminal", it displays the results in the VSCode internal terminal, and displays the current environment and the path of the running file.

Reference: console.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
1

If you use code-runner extension,

open settings.json (ctrl + shift + p then type settings.json) then add this

"code-runner.executorMap": {
    "python": "<console clear> && <python or your python version> -u",
},
"code-runner.clearPreviousOutput": true,
"code-runner.showExecutionMessage": false,
"code-runner.runInTerminal": true,

In my case i replaced

<console clear> with clear (since i am on wsl)

&&

<python or your python version> with python3.10

shaderone
  • 408
  • 9
  • 21
  • And this allows for user input also? Not sure if its appropriate but can you post what your out put looks like ? And the settings.json you created? – Michael1775 Feb 06 '22 at 02:03
  • Yeah, you can input values. https://ibb.co/tpNKGmp (quick tip use oh my zsh to make the terminal even more minimal) is this what you are looking for? @Jarhead1775 *pressing the code runner RUN button will first clear the console and then runs your program.* – shaderone Feb 06 '22 at 06:10
0

The above answer works for displaying the output as desired however if you want to hide the long path

use prompt [text]

For example, the following command sets "> (greater-than sign)" as prompt

prompt $g

if you want to return back to showing full path just type prompt and press Enter.

-2

Donwload code-runner extension in VsCode, then unchecked Code-runner:Show Execution Message in setting of code-runner extension. enter image description here