summaryrefslogtreecommitdiffstats
path: root/Doc/ref
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-06-26 19:26:40 (GMT)
committerGuido van Rossum <guido@python.org>1996-06-26 19:26:40 (GMT)
commit7710f1f00c253ee0b35fc6ae5783e958273e0e49 (patch)
tree5b1b28d817c1986741a4b90d42b93ceec8c54f8a /Doc/ref
parent00ed6a3279371854400902ce8ef437d3225ef285 (diff)
downloadcpython-7710f1f00c253ee0b35fc6ae5783e958273e0e49.zip
cpython-7710f1f00c253ee0b35fc6ae5783e958273e0e49.tar.gz
cpython-7710f1f00c253ee0b35fc6ae5783e958273e0e49.tar.bz2
explain global better
Diffstat (limited to 'Doc/ref')
-rw-r--r--Doc/ref/ref6.tex17
1 files changed, 15 insertions, 2 deletions
diff --git a/Doc/ref/ref6.tex b/Doc/ref/ref6.tex
index 22575c2..54bfde5 100644
--- a/Doc/ref/ref6.tex
+++ b/Doc/ref/ref6.tex
@@ -481,14 +481,14 @@ global_stmt: "global" identifier ("," identifier)*
\end{verbatim}
The \verb@global@ statement is a declaration which holds for the
-entire current scope. It means that the listed identifiers are to be
+entire current code block. It means that the listed identifiers are to be
interpreted as globals. While {\em using} global names is automatic
if they are not defined in the local scope, {\em assigning} to global
names would be impossible without \verb@global@.
\indexiii{global}{name}{binding}
Names listed in a \verb@global@ statement must not be used in the same
-scope before that \verb@global@ statement is executed.
+code block before that \verb@global@ statement is executed.
Names listed in a \verb@global@ statement must not be defined as formal
parameters or in a \verb@for@ loop control target, \verb@class@
@@ -499,6 +499,19 @@ restrictions, but programs should not abuse this freedom, as future
implementations may enforce them or silently change the meaning of the
program.)
+Note: the \verb@global@ is a directive to the parser. Therefore, it
+applies only to code parsed at the same time as the \verb@global@
+statement. In particular, a \verb@global@ statement contained in an
+\verb@exec@ statement does not affect the code block {\em containing}
+the \verb@exec@ statement, and code contained in an \verb@exec@
+statement is unaffected by \verb@global@ statements in the code
+containing the \verb@exec@ statement. The same applies to the
+\verb@eval()@, \verb@execfie()@ and \verb@compile()@ functions.
+\stindex{exec}
+\ttindex{eval}
+\ttindex{execfile}
+\ttindex{compile}
+
\section{The {\tt access} statement} \label{access}
\stindex{access}