In order to remove file path displayed in Terminal of VsCode I use
print("\033c")
at the first line of each of my Python script files. Is it possible to make this line be the first line of each Python script file by default?
-
1Does [this answer](https://stackoverflow.com/questions/61176552/how-to-hide-file-paths-when-running-python-scripts-in-vs-code) solve your issue? Btw, code-runner extension can also do it. Adding these codes to settings.json: "code-runner.runInTerminal": false, "code-runner.clearPreviousOutput": true, "code-runner.showExecutionMessage": false, – MingJie-MSFT Feb 22 '23 at 01:32
-
@MingJie-MSFT Actually, I found the print("\033c") from the post you linked! I tried the method in the accepted answer, but it causes issue for input() function so I decided to simply erase the text by this line of script. – Etemon Feb 22 '23 at 10:03
-
@MingJie-MSFT About second part of your comment: I did it but it gives Syntax Error, not sure why. – Etemon Feb 22 '23 at 14:53
-
The second method requires you to install the [code-runner extension](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner). – MingJie-MSFT Feb 23 '23 at 01:11
-
@MingJie-MSFT I didn't want to disturb you. I still have the problem with blue lines of text. The script in my setting.jaosn is: ``{ "explorer.confirmDelete": false, "tabnine.experimentalAutoImports": true, "code-runner.runInTerminal": false, "code-runner.clearPreviousOutput": true, "code-runner.showExecutionMessage": false, "[python]": { "editor.formatOnType": true },`` – Etemon Feb 28 '23 at 13:07
-
@MingJie-MSFT Now that I installed Anaconda for ML programming, I used Spyder and it runs the script pretty quick without any issues. So problem is solved ;) – Etemon Mar 04 '23 at 15:30
-
@MingJie-MSFT Thanks! It's kind of you. Ok it makes sense, I'm going to do it. – Etemon Mar 06 '23 at 11:48
2 Answers
You can do even better (somewhat opinionated whether this is really better) using the PYTHONSTARTUP
environment variable:
If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode.
If you're using a launch.json
file to define debugging profiles, then you can probably use the env
field to define PYTHONSTARTUP
to point to a file that you define in your workspace that contains that line, like "env": "${workspaceFolder}/path/to/startup.py"
. If you're using the integrated terminal, use the terminal.integrated.env.<platform>
settings.
Also, your choice of ESC c
is a bit overkill I think. Do you really want to trigger a Full reset to initial terminal state when running any of your scripts? There are better solutions to hide a file path that gets printed by VS Code like simply clearing the screen, which you can do with CSI 2 J
or CSI 3 J
(2
means clear entire screen, and 3
means to clear entire screen and wipe the scrollback buffer).

- 20,030
- 7
- 43
- 238
-
Thanks for the help! Actually, I'm new to programming and found the code "print("\033c")" on the internet. So as your suggestion on second part of the answer, I tried print('\033CSI2J') but it doesn't work. Can you please help me? (again, sorry if I'm newbie). – Etemon Feb 22 '23 at 09:59
-
1I believe it would be `\033[2J` (info courtesy of [the wikipedia article linked in the post](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences)) – starball Feb 22 '23 at 16:41
Here is how I solved the issue:
I needed to install Anaconda in my PC for Machine Learning purposes. After spending some times on writing python scripts on spyder and Jupyter Notebook, I hadn't any issue in program running. So I choose spyder over VsCode.

- 53
- 2
- 11