In some cases, programs will fail to compile. In other cases, names that were previously resolved using the global namespace will be resolved using the local namespace of an enclosing function. In Python 2.1, warnings will be issued for all statements that will behave differently. Specification Python is a statically scoped language with block structure, in the traditional of Algol. A code block or region, such as a module, class definition, or function body, is the basic unit of a program.
Names refer to objects.
Names are introduced by name binding operations. Each occurrence of a name in the program text refers to the binding of that name established in the innermost function block containing the use. The name binding operations are argument declaration, assignment, class and function definition, import statements, for statements, and except clauses. If a name is bound anywhere within a code block, all uses of the name within the block are treated as references to the current block. If the global statement occurs within a block, all uses of the name specified in the statement refer to the binding of that name in the top-level namespace.