NameError when assigning dictionary values

Fredrik Lundh effbot at telia.com
Sun Apr 2 18:39:27 EDT 2000


lewst <lewst at yahoo.com> wrote:
> > You're creating two empty lists, both named "value".The first
> > is thown away by creating the second. Nowhere are "one" and
> > "two" variable names, hence the NameError.
>
> Ok.  So now how do I get the program to do what I want?

dunno.  what *do* you want?

if you want to access the dictionary members you just
created, use dictionary syntax:

    print mydict["one"], mydict["two"]

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.

(there are ways to create variables on the fly, but they're
all rather obscure and not very efficient -- so you don't really
want that.  but sure, if you can give me a very good reason...)

</F>





More information about the Python-list mailing list