Python, as a versatile and accessible programming language, can be run on various platforms using a wide range of tools and IDEs (Integrated Development Environments). However, for those who prefer a minimalist approach or are just starting out, running Python code with a simple text editor and the command line can be a great way to get started. In this article, we will discuss how to use a basic text editor like Notepad (on Windows) or TextEdit (on macOS) to write Python scripts and execute them using the command line.
Step 1: Install Python
Before you can run Python code, you need to ensure that Python is installed on your computer. You can download and install Python from the official Python website (https://www.python.org/downloads/). During the installation process, make sure to check the box that adds Python to your system’s PATH variable, as this will allow you to run Python from any location in the command line.
Step 2: Write Your Python Code
Open your favorite text editor (e.g., Notepad, TextEdit, or any other plain text editor). Then, write your Python code in the editor. For example, let’s create a simple script that prints “Hello, world!” to the console.
python# hello_world.py
print("Hello, world!")
Step 3: Save Your Script

Once you’ve written your code, save the file with a .py
extension. For our example, let’s name the file hello_world.py
. Make sure to remember the location where you saved the file, as you will need to navigate to that location in the command line later.
Step 4: Open the Command Line

Next, open the command line or terminal on your computer. The process for opening the command line varies depending on your operating system:
- Windows: Press the Windows key, type “cmd,” and press Enter.
- macOS/Linux: Open the Terminal application (usually found in the Utilities folder within Applications).
Step 5: Navigate to Your Script’s Location
In the command line, use the cd
command to change the current directory to the location where you saved your Python script. For example, if you saved hello_world.py
in the Documents
folder on Windows, you would type:
bashcd Documents
On macOS or Linux, the path might look something like this:
bashcd ~/Documents
Step 6: Execute Your Script

Finally, use the Python interpreter to execute your script. Type python
followed by the name of your script (including the .py
extension) and press Enter. For our example, you would type:
bashpython hello_world.py
If everything is set up correctly, the Python interpreter will run your script, and you should see the output “Hello, world!” printed in the command line.
Conclusion

Running Python code with a simple text editor and the command line is a straightforward and accessible way to get started with Python programming. By following the steps outlined in this article, you can write and execute your own Python scripts without needing to install any additional software or IDEs. As you become more familiar with Python, you may want to explore more advanced tools and IDEs that offer additional features and functionality, but for beginners, this minimalist approach can be a great starting point.
78TP is a blog for Python programmers.