Existance of of variable

Terry Reedy tjreedy at udel.edu
Mon Jul 4 17:38:34 EDT 2005


"tiissa" <tiissa at nonfree.fr> wrote in message 
news:42c98b40$0$29947$626a14ce at news.free.fr...
> Variables are stored in two dictionnaries: globals() (for global
> variables) and locals() (for the local ones, which are also global on
> top level).

Within a function, the local namespace is usually *not* a dictionary.
D=locals() makes a dictionary copy of the namespace,
which takes more time than one might expect, and
which has the trap that changes to D do *not* affect the namespace itself.
So the try..except idiom is faster and does not have that particular trap.

Terry J. Reedy







More information about the Python-list mailing list