GNU Info

Info Node: (python2.1-ref.info)global statement

(python2.1-ref.info)global statement


Next: exec statement Prev: import statement Up: Simple statements
Enter node , (file) or (file)node

The `global' statement
======================

     global_stmt:    "global" identifier ("," identifier)*

The `global' statement is a declaration which holds for the entire
current code block.  It means that the listed identifiers are to be
interpreted as globals.  While _using_ global names is automatic if
they are not defined in the local scope, _assigning_ to global names
would be impossible without `global'.

Names listed in a `global' statement must not be used in the same code
block textually preceding that `global' statement.

Names listed in a `global' statement must not be defined as formal
parameters or in a `for' loop control target, `class' definition,
function definition, or `import' statement.

(The current implementation does not enforce the latter two
restrictions, but programs should not abuse this freedom, as future
implementations may enforce them or silently change the meaning of the
program.)

*Programmer's note:* the `global' is a directive to the parser.  It
applies only to code parsed at the same time as the `global' statement.
In particular, a `global' statement contained in an `exec' statement
does not affect the code block _containing_ the `exec' statement, and
code contained in an `exec' statement is unaffected by `global'
statements in the code containing the `exec' statement.  The same
applies to the `eval()', `execfile()' and `compile()' functions.


automatically generated by info2www version 1.2.2.9