In the spirit of the season, I have here revised my "Hello, World!" tutorial to offer the appropriate holiday greetings of the three monotheistic religions in one of three languages. At the end of the tutorial, you will be able to feed it a line like
and it will reply
">./MerryChristmas.py susie christian french !"
"Joyeux Noël, Susie!" As this tutorial is in lieu of the "Hello, World!" section, let's give honourable mention to that historic lesson. Start up your favorite editor and save the following into a file:
print "Hello, World!"
To execute this program, save it with a suffix of '.py' (e.g., HelloWorld.py) and type 'python' and the filename in a shell like this:The output is predictable:
> python HelloWorld.pyHello, World!
If you prefer to execute it by its name, instead of as an argument to the Python interpreter, put a "bang" line at the top. Include the following on the first line of the program, substituting the absolute path to the Python interpreter for '/path/to/python':Be sure to change the permission on the file to allow execution, if necessary for your operating system.
Unlike the usual "Hello, World!" program that functions in plain text, or ASCII, our little program needs to output non-English character sets. To enable Unicode support in the program, we tell Python that the program is written in Unicode. Immediately after the bang line, add this:
# -*- coding: utf-8 -*-
Now, let's take this idea and embellish it a bit according to what I outlined above.