Is it possible to make a line of script (print("33c")) added by default to the beginning of Python files in VSCode?

Question:

In order to remove file path displayed in Terminal of VsCode I use
print("33c") 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?

Asked By: Etemon

||

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".

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).

Answered By: user

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.

Answered By: Etemon