Linux/Unix > Python Essential Reference, Second Edition > 10. Execution Environment > Launching Python Applications | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238111161105082191049133047181010

### 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 launches the editor that was used to create the file. However, two special programs in the Macintosh distribution can be used to build applications. Dropping a `.py` file on the `BuildApplet` program converts the program into a file that automatically launches the Python interpreter when opened. The `BuildApplication` program converts a Python program into a standalone application that can be distributed and executed on machines that don’t have a Python installation.

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.