1. Home
  2. Computing & Technology
  3. Python

Executing a Python Program: Shell or File?

From , former About.com Guide

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

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

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

All rights reserved.