Reputation: 18194
Now I am running the python file everytime like this:
python C:/my/path/to/python/file.py
I want to replace it with one word command like this
myfile
The same command should work from command_prompt, powershell and powershell_ise and it should work from any directory that I am in.
Upvotes: 0
Views: 2435
Reputation: 3987
You can basically create Custom Environment Variables
. This link will guide how can you do that.
Link: Create Custom Environment Variables in Windows
The file option is interesting because it means you can also create an environment variable to launch a program. For example, you can point an environment variable to any EXE file on your system. When you invoke the variable, it will launch the program. If you have a custom executable program file stored in some random directory on your PC, this is an easy way to launch it without having to go look for it.
Or if you want to run your python script from anywhere, technically not anywhere but from other directory also then you can create a .bat
file. And opening that .bat
will automatically run your python script. You can create a .bat
by :
script.bat
.script.bat
and open it in Notepad.python C:/my/path/to/python/file.py
script.bat
.
It will automatically run you file.py
from here. You can place script.bat
in your preferred place like in desktop
.Upvotes: 1
Reputation: 13
If you made the python an exe and cd into the directory or add it to your environment variables you could call it by myfile or myfile.exe
Another way would be to make a batch file that contains
python C:/my/path/to/python/file.py
and name it myfile which would allow you to call the batch file and it would type out the rest
Also if you cd into C:/my/path/to/python you could type python file.py instead of the whole path.
Upvotes: 1