1. Home
  2. Computing & Technology
  3. Python

Executing a Python Program: Shell or File?

By Al Lukaszewski, About.com

3 of 4

Executing Python Program Files: Do It With a Bang (Line)

Most programmers write their programs to stand alone, independent of the live environment. They save their programs in a text file and, instead of saving the file with a 'txt' suffix, save it with a 'py' suffix. This indicates to the computer and the programmer that the file is actually a Python program. Then the Python interpreter is invoked to read and interpret the file. Depending on one's platform, this happens in one of two ways.

On Mac, Linux, and other Unix-like platforms, one can simply put a "bang" line as the first line of the program. This "bang" line indicates the location on the harddrive of the Python interpreter and reads as follows:

#!/path/to/interpreter

Index: Executing a Python Program: Shell or File?

  1. Programming: Pointless Without Execution
  2. Python's Live Interpreter: Execution as a Shell Game
  3. Executing Python Program Files: Do It With a Bang (Line)
  4. Invoking the Python Interpreter: "Hello, Dmitri?" Does Not Work

3 of 4

Explore Python

More from About.com

  1. Home
  2. Computing & Technology
  3. Python

©2008 About.com, a part of The New York Times Company.

All rights reserved.