Launching Python Applications

In most cases, you’ll want programs to start the interpreter automatically, rather than first having to start the interpreter manually. On UNIX, this is done using shell scripts by setting the first line of a program to something like this:

#!/usr/local/bin/python 
# Python code from this point on... 
import string 
print "Hello world" 
... 

On Windows, double-clicking a .py, .pyw, .wpy, .pyc, or .pyo file automatically launches the interpreter. Normally, programs run in a console window unless they’re renamed with a .pyw suffix (in which case the program runs silently). If it’s necessary to supply options to the interpreter, Python can also be started from a .bat file.

On the Macintosh, clicking a .py file normally ...

Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.