Creating variables from dicts

Gregory Ewing greg.ewing at
Thu Feb 25 08:55:51 CET 2010

Luis M. González wrote:

> I still don't understand why is it a bad idea in the case of
> globals().
> This is the only way I know to define variables programatically in the
> top-level namespace, without having to do it manually one by one.

The point is that creating variables whose names are computed
at run time is usually a misguided thing to do in the first

Think about it -- how are you going to *use* those variables
that you've created?

If the answer is that you're going to go looking for a way
to read the values of variables whose names are computed at
run time, you might as well not use variables at all, but
just keep their values in a dictionary.


More information about the Python-list mailing list