Skip to content

Latest commit

 

History

History
266 lines (195 loc) · 10.3 KB

File metadata and controls

266 lines (195 loc) · 10.3 KB

Execution model

.. index::
   single: execution model
   pair: code; block

Structure of a program

.. index:: block

A Python program is constructed from code blocks. A :dfn:`block` is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block. A script file (a file given as standard input to the interpreter or specified as a command line argument to the interpreter) is a code block. A script command (a command specified on the interpreter command line with the :option:`-c` option) is a code block. The string argument passed to the built-in functions :func:`eval` and :func:`exec` is a code block.

.. index:: pair: execution; frame

A code block is executed in an :dfn:`execution frame`. A frame contains some administrative information (used for debugging) and determines where and how execution continues after the code block's execution has completed.

Naming and binding

.. index::
   single: namespace
   single: scope

Binding of names

.. index::
   single: name
   pair: binding; name

:dfn:`Names` refer to objects. Names are introduced by name binding operations.

.. index:: single: from; import statement

The following constructs bind names: formal parameters to functions, :keyword:`import` statements, class and function definitions (these bind the class or function name in the defining block), and targets that are identifiers if occurring in an assignment, :keyword:`for` loop header, or after :keyword:`as` in a :keyword:`with` statement or :keyword:`except` clause. The :keyword:`import` statement of the form from ... import * binds all names defined in the imported module, except those beginning with an underscore. This form