Description
A developer's journey through code. I build, I break, and I write about it. Explore articles on modern software development, programming tips, and more.
An alias serves as a personalized shorthand or nickname for a more extended command or sequence of commands, enabling users to streamline repetitive tasks. In this guide, I will walk you through the setup of Python3 aliases on both Windows and Ubuntu/Linux systems.
On Windows, you can establish an alias by crafting a batch file to function as the alias. Follow these steps:
In Notepad, enter the following batch commands:
@echo off
python %*
The '@echo off' line disables command echoing to the console, enhancing script cleanliness, while 'python %*' calls the python3 executable with any additional arguments passed to the batch file.
Save the file with a .bat extension, for example, python.bat.
Test the alias by navigating to the directory containing the Python script in the command prompt and executing 'python hello.py' (replace 'hello.py' with your script).
You can format the bashrc to add an alias for python3 which will enable you call it using python.
Simple Alias Creation Using Nano:
Open the shell configuration file (e.g., '~/.bashrc' for Bash) in a text editor:
nano ~/.bashrc
Add the following line at the end of the file:
alias python=python3
Save (ctrl+o, enter) and exit (ctrl+x) the editor.
Reload the shell configuration with:
source ~/.bashrc
Now, typing 'python' will reference Python3. Verify with 'python --version'.
Using Vi Editor for Python3 Alias:
Open the text editor using Vi:
vi ~/.bashrc
Navigate to the end of the file, press 'i' to enter insert mode, and add:
alias python=python3
Exit insert mode ('Esc'), save and exit with ':wq', and press Enter.
Reload the shell configuration:
source ~/.bashrc
Now, 'python' denotes Python3.
Aliases enhance efficiency by providing shorter, memorable names for frequently used commands. This guide demonstrates the creation of a 'python' alias for Python3 on both Ubuntu/Linux and Windows using various methods. The process is more straightforward on Ubuntu/Linux. Consider applying aliases to other commands to further streamline your workflow and boost productivity. If you have any question or have something to add, you can do that in the comments section below.
Cookies improve user experience on SunshineIHCTS. By continuing to use this website, you consent to the use of cookies in accordance with the Privacy policy.
A developer's journey through code. I build, I break, and I write about it. Explore articles on modern software development, programming tips, and more.
Comments section
You need to be logged in to comment, Login or Register.Approved comments:
No comments yet! be the first to comment