Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make keyword for python script "python filename.py"

I am trying to create an alias for python filename.py so I can use my_keyword to run my script file.

Example:

python filename.py
python filename.py

Need to convert to

my_keyword

So this will call my file.

Is it possible? If it is possible then How I can achieve this.

like image 209
Akshay Jain Avatar asked Aug 25 '26 02:08

Akshay Jain


1 Answers

If you're using Linux, MacOS, or some other Unix-based environment, rename the file to my_keyword and use a shebang line to make it use the Python interpreter, and make the file executable. Then make sure the file is in a directory that's in your shell PATH.

mv filename.py my_keyword
chmod +x my_keyword

Make sure the first line of the file is:

#!/usr/bin/env python

This tells the shell to run Python and to interpret the contents of the file.

You may want to install the file in /usr/local/bin, or add ~/bin to your PATH, so that you can execute the file without entering the full path.

like image 99
Jim Stewart Avatar answered Aug 27 '26 00:08

Jim Stewart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!