Implementation of the global statement

Martin v. Löwis loewis at informatik.hu-berlin.de
Wed Nov 27 09:11:09 EST 2002


Michael Hudson <mwh at python.net> writes:

> > Yes, you guessed right, out of pure curiosity: is this list
> > accessible from Python? 
> 
> Don't think so, as the list only exists during compiling and you can't
> hook into it or only execute one phase of it.

To some degree, you can find out by looking at co_names, and removing
all names which are also in co_varnames (both are attributes of the
code object).

Of course, you can't tell afterwards if a global name was considered
global because there was no assignment to it, or whether there was a
global declaration. Also, globals that are not used don't appear in
co_names.

HTH,
Martin




More information about the Python-list mailing list