NameError when assigning dictionary values

lewst lewst at
Sun Apr 2 19:17:57 EDT 2000

Fredrik Lundh <effbot at> wrote:

> if you want to create variables in the local namespace
> on the fly, you're obviously trying to emulate some other
> programming language (Tcl?) in Python.  that's usually a 
> rather bad idea.

I was trying to build a dictionary and create lists corresponding to
the value names in the dictionary in one loop.

Do I really have to type "one" and "two" twice?  Once to make it a
variable and a second time to add to my dictionary?  I.e,

>>> one, two = [], []

>>> mydict = { ".": one, "+": two }

This seems error prone if the the number of variables grows very large
as it will for me.

Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.

More information about the Python-list mailing list