Implementation of the global statement

Michael Hudson mwh at python.net
Wed Nov 27 08:37:19 EST 2002


hungjunglu at yahoo.com (Hung Jung Lu) writes:

> The global statement as in
> 
> def f(x):
>     global y
>     ...
> 
> is a directive to the parser. 

Well, compiler, really.

> Internally the parser must keep a list of the "locally-globalled"
> names.

Yup, at least on some level.

> 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.

> If not, why not? :)

See above.  You can probably get the compiler package to do what you
want.

Cheers,
M.

-- 
48. The best book on programming for the layman is "Alice in
    Wonderland"; but that's because it's the best book on
    anything for the layman.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list