12. Using Python with Different Text Editors
1. Introduction
Python code can be written in any plain text editor.
While IDEs like VS Code and PyCharm are powerful, sometimes a simple text editor is faster and more lightweight.
In this chapter, we’ll explore using Python with several popular text editors.
2. Notepad (Windows)
- The simplest editor available on Windows.
- Steps:
-
Open Notepad.
-
Write a Python program, for example:
print("Hello from Notepad!") -
Save the file with the
.pyextension (e.g.,hello.py).- Select Save as type → All Files.
- Encoding: UTF-8.
-
Run the file from Command Prompt with:
python hello.py
-
3. TextEdit (macOS)
- The built-in text editor for macOS.
- Steps:
-
Open TextEdit.
-
Go to Format → Make Plain Text.
-
Write Python code and save it with
.pyextension (e.g.,hello.py). -
Run from Terminal with:
python3 hello.py
-
4. Nano (Linux/macOS Terminal Editor)
- A simple terminal-based text editor.
- Steps:
-
Open Terminal.
-
Create a new file with:
nano hello.py -
Write Python code inside.
-
Save with Ctrl + O, exit with Ctrl + X.
-
Run with:
python3 hello.py
-
5. Vim and Neovim
- Powerful modal text editors for advanced users.
- Steps:
-
Install Vim:
sudo apt install vim # Ubuntu/Debian
sudo pacman -S vim # Arch
brew install vim # macOS -
Create a Python file:
vim hello.py -
Press i to enter insert mode, write Python code.
-
Save and quit: Esc → :wq.
-
Run as usual:
python3 hello.py
-
6. Sublime Text
- A fast, extensible editor with Python plugins.
- Installation: https://www.sublimetext.com/
- Steps:
- Open Sublime Text.
- Write Python code.
- Save with
.pyextension. - Install the SublimeREPL plugin for running Python inside Sublime.
7. Atom (Discontinued, still usable via forks)
- Atom was discontinued, but forks like Pulsar exist.
- Features include extensions and integrated terminals.
8. Why Use Text Editors?
- Lightweight compared to IDEs.
- Universal — works on any OS.
- Customizable — plugins, syntax highlighting, linting.
9. Next Steps
✅ You now know how to write Python code in various text editors.
In the next chapter, we’ll look at the difference between Python scripts and modules.