Invoking the Interpreter


Python scripts are executed by a Python interpreter. On most systems, you can start the Python interpreter by executing the python command at a console prompt. However, this can vary based on the system and development environment you have set up. This section discusses the standard methods to invoke the interpreter to execute Python statements and script files.

Invoking the interpreter without passing a script file as a parameter brings up the following prompt:

bwd-linux:/book # python Python 2.4.2 (#1, Apr  9 2006, 19:25:19) [GCC 4.1.0 (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or     "license" for more information. >>>


The Python prompt is indicated by >>>. If you execute a command that requires more input, a ... prompt will be displayed. From the interpreter prompt, you can execute individual Python statements, as follows:

>>> print "Printing a String" Printing a String


Invoking the interpreter with a script parameter, as shown next, begins execution of the script and continues until the script is finished. When the script is finished, the interpreter is no longer active.

bwd-linux:/book # python script.py Executing a Script bwd-linux:/book #


Scripts can also be executed from within the interpreter using the execfile(script) function built in to Python. The following example shows a script being executed using the execfile() function:

>>> execfile("script.py") Executing a Script >>>




Python Phrasebook(c) Essential Code and Commands
Python Phrasebook
ISBN: 0672329107
EAN: 2147483647
Year: N/A
Pages: 138
Authors: Brad Dayley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net