After I run my python code on the terminal, it displays a few paths in the 1st line and then the actual output of my code in the 2nd line. Can I hide the 1st line so I only see the output?
-
Put the path to python in windows environement variables at the and of PATH – JB_DELR Sep 05 '20 at 21:41
-
1The 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
-
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
3 Answers
- You could use the following settings in
launch.jsonin the.vscodefolder, 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.
- 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:
- 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.
- 7,195
- 1
- 13
- 22
-
**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
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.
- 61
- 5
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
- 306
- 6
- 16
-
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.* – Pixie Dust Feb 06 '22 at 06:10