A.4 How to Write and Run a Python Program
315
A.4.2 Text Editors
The most widely used editors for writing programs are Emacs and Vim, which are
available on all major platforms. Some simpler alternatives for beginners are
• Linux: Gedit
• Mac OS X: TextWrangler
• Windows: Notepad++
We may mention that Python comes with an editor called Idle, which can be used
to write programs on all three platforms, but running the program with commandline arguments is a bit complicated for beginners in Idle so Idle is not my favorite
recommendation.
Gedit is a standard program on Linux platforms, but all other editors must be
installed in your system. This is easy: just google the name, download the file, and
follow the standard procedure for installation. All of the mentioned editors come
with a graphical user interface that is intuitive to use, but the major popularity of
Emacs and Vim is due to their rich set of short-keys so that you can avoid using the
mouse and consequently edit at higher speed.
A.4.3 Terminal Windows
To run the Python program, you may use a terminal window. This is a window
where you can issue Unix commands in Linux and Mac OS X systems and DOS
commands in Windows. On a Linux computer, gnome-terminal is my favorite, but
other choices work equally well, such as xterm and konsole. On a Mac computer,
launch the application Utilities—Terminal. On Windows, launch PowerShell.
You must first move to the right folder using the cd foldername command.
Then running a python program prog.py is a matter of writing python prog.py.
Whatever the program prints can be seen in the terminal window.
A.4.4 Using a Plain Text Editor and a Terminal Window
1. Create a folder where your Python programs can be located, say with name
mytest under your home folder. This is most conveniently done in the terminal
window since you need to use this window anyway to run the program. The
command for creating a new folder is mkdir mytest.
2. Move to the new folder: cd mytest.
3. Start the editor of your choice.
4. Write a program in the editor, e.g., just the line print(’Hello!’). Save the
program under the name myprog1.py in the mytest folder.
5. Move to the terminal window and write python myprog1.py. You should see
the word Hello! being printed in the window.
Précédent

- 333/350

Suivant