Home arrow Python arrow How Python Runs Programs

How Python Runs Programs

Python is a language and an interpreter that executes other programs. Get a quick look at program execution, how to launch code and how Python runs it. This chapter is from Learning Python, second edition, by Mark Lutz and David Ascher (ISBN: 0-596-00281-5, O'Reilly, 2003).

  1. How Python Runs Programs
  2. Program Execution
  3. Python Virtual Machine (PVM)
  4. Execution Model Variations
  5. The Psyco Just-in-Time Compiler
  6. Future Possibilities?
By: O'Reilly Media
Rating: starstarstarstarstar / 38
July 06, 2004

print this article





This chapter and the next give a quick look at program execution—how you launch code, and how Python runs it. In this chapter, we explain the Python interpreter. Chapter 3 will show you how to get your own programs up and running.

Startup details are inherently platform-specific, and some of the material in this chapter may not apply to the platform you work on, so you should feel free to skip parts not relevant to your intended use. In fact, more advanced readers who have used similar tools in the past, and prefer to get to the meat of the language quickly, may want to file some of this chapter away for future reference. For the rest of you, let’s learn how to run some code.

Introducing the Python Interpreter

So far, we’ve mostly been talking about Python as a programming language. But as currently implemented, it’s also a software package called an interpreter. An interpreter is a kind of program that executes other programs. When you write Python programs, the Python interpreter reads your program, and carries out the instructions it contains. In effect, the interpreter is a layer of software logic between your code and the computer hardware on your machine.

When the Python package is installed on your machine, it generates a number of components—minimally, an interpreter and a support library. Depending on how you use it, the Python interpreter may take the form of an executable program, or a set of libraries linked into another program. Depending on which flavor of Python you run, the interpreter itself may be implemented as a C program, a set of Java classes, or other. Whatever form it takes, the Python code you write must always be run by this interpreter. And to do that, you must first install a Python interpreter on your computer.

Python installation details vary per platform, and are covered in depth in Appendix A. In short:

  • Windows users fetch and run a self-installing executable file, which puts Python on their machine. Simply double-click and say Yes or Next at all prompts.

  • Linux and Unix users typically either install Python from RPM files, or compile it from its full source-code distribution package.

  • Other platforms have installation techniques relevant to that platform. For instance, files are synched on Palm Pilots.

Python itself may be fetched from the downloads page at Python’s web site, www. python.org. It may also be found through various other distribution channels. You may have Python already available on your machine, especially on Linux and Unix. If you’re working on Windows, you’ll usually find Python in the Start menu, as captured in Figure 2-1 (we’ll learn what these menu items mean in a moment). On Unix and Linux, Python probably lives in your /usr directory tree.


Because installation details are so platform-specific, we’ll finesse the rest of this story here. (For more details on the installation process, consult Appendix A.) For the purposes of this chapter and the next, we’ll assume that you’ve got Python ready to go.

Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

Visit the O'Reilly Network http://www.oreillynet.com for more online content.

>>> More Python Articles          >>> More By O'Reilly Media

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: