0

so I'm running python on studio visual code with the extension code runner. enter image description here

As you can see I have a file named fart.py, I'm running the output to the terminal because I'm handling user input. But whenever I run the code it doesn't refresh so I have everything from previous runs, and it gives me the path information ( PS C:\Users\Pluto\OneDrive\Desktop\python stuff> & C:/Users/Pluto/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/Pluto/OneDrive/Desktop/python stuff/fart.py" ).

I don't want to see the paths and I would like to have the terminal refresh every time I run some code. I've looked around online, looked through the settings and I can't really find anything. Thanks for the help.

pouchela
  • 31
  • 3
  • 1
    Printing the path is the standard behavior. That's part of the prompt and has nothing to do with VS Code, or Python, but you can change it [with one of these settings](https://superuser.com/questions/315354/how-do-i-hide-the-path-in-command-line-prompt-on-windows). You can clear the terminal with `clear`, or by using [one of these](https://stackoverflow.com/a/518007/5774952) in your script if that's what you'd prefer. – Zac Anger Jan 02 '23 at 03:39
  • VS Code could clear the screen for you if you want. See [this](https://stackoverflow.com/questions/48713604/how-can-i-clear-the-terminal-in-visual-studio-code). – afarrag Jan 02 '23 at 03:58
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – user11717481 Jan 02 '23 at 09:38
  • 1
    Please don't post screenshots of textual output, post it as code formatted text and ensure your provide a [mre]. – Mark Rotteveel Jan 04 '23 at 10:54

2 Answers2

0

How can Code Runner run the code? It runs commands automatically, therefore we don't need to do that manually, but as you see, commands are still necessary. The only difference is that the extension itself runs the commands.

Unfortunately, it's not supported to configure what you need in Code Runner... So think just like you do it manually? For example, you can execute Terminal: Clear in Command Palette to "refresh the terminal".

I hope that may help you.

p.s. The comment from Zac Anger gives a great solution by code. Just edit code-runner.executorMap setting accordingly and everything can go well.

0

You can add the following code to your settings.json:

  "code-runner.runInTerminal": false,
  "code-runner.clearPreviousOutput": true,
  "code-runner.showExecutionMessage": false,

In this way, the path will not be displayed each time you run file, and the last run result will be cleared automatically each time you run if you use code-runner extension.

Example:

test.py:

print("hello")

Output:

enter image description here

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13