Loupi
Loupi

Reputation: 580

How can I make python import a module as soon as it is Invoked in terminal?

I hate working in a clogged screen so as soon as I start working in the terminal I define a function as follow:

from os import system

cls = lambda: system('cls')

This way I can clear my window with the simple command cls().

Is there a way that I can make python import that function as soon as I invoke the interpreter with the command python. Similarly as to how __builtins__ gets imported.

This question is not just pertained to wanting to do this because I'm lazy to type 2 extra lines at every invoke, I also want to know a way that I can make python automatically import any module of my own making and where I should store that script.

Upvotes: 2

Views: 295

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180391

On windows you need to set the PYTHONSTARTUP environment variable in something like Security-System-advanced-environment variables:

Firts create a file pythonstartup.py with your code inside:

from os import system

cls = lambda: system('cls')

Then in your environment variables set PYTHONSTARTUP="C:\path_to\pythonstartup.py"

Upvotes: 2

Related Questions