Running a shortest Python program

We need a one line Python program that will prove that the Python interpreter is installed and working on our computer platform.

How to do it...

  1. Create a folder (directory) called something like construction_work or constr for short. You will place all your Python programs inside this directory. In a text editor such as gedit on Linux or notepad on Windows. If we are working in Windows, there is a nice editor called "Context" that can be downloaded for free from http://www.contexteditor.org/ Context, that is sensitive to Python syntax and has a search-and-replace function that is useful.
  2. Type the following line:
    Print 'My wereld is "my world" in Dutch'
  3. Save this as a file named simple_1.py, inside the directory called constr.
  4. Open up an X terminal or a DOS window if you are using MS Windows.
  5. Change directory into constr - where simple_1.py is located.
  6. Type python simple_1.py and your program will execute. The result should look like the following screenshot:
    How to do it...
  7. This proves that your Python interpreter works, your editor works, and that you understand all that is needed to run all the programs in this book. Congratulations.
    """
    Program name: simplest_1.py
    Objective: Print text to the screen.
    
    Keywords: text, simplest
    =========================
    Printed "mywereld" on terminal.
    Author:          Mike Ohlson de Fine
    
    """
    Print 'mywereld is "my world" in Dutch'

How it works...

Any instructions you type into a Linux X terminal or DOS terminal in MS Windows are treated as operating system commands. By starting these commands from within the same directory where your Python program is stored you do not have to tell the Python and operating system where to search for your code. You could store the code in another directory but you would then need to precede the program name with the path.

There's more...

Try the longer version of the same basic print instructions shown in the following program.

All the text between the """ (triple quotation marks) is purely for the sake of good documentation and record keeping. It is for the use of programmers, and that includes you. Alas, the human memory is imperfect. Bitter experience will persuade you that it is wise to provide fairly complete information as a header in your programs as well as comments inside the program.

However, in the interest of saving space and avoiding distractions, these header comments have been left out in the rest of this book.