Creating variables from dicts

G

Gregory Ewing

Luis said:
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
place.

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

Aahz

Actually, a tuple is made with commas...the parens are just there
to clarify the order of operations and make it easier to read :)

(1, 2, 3)

Almost true:
()

Parentheses are definitely needed for the empty tuple.
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top