NameError when assigning dictionary values

Michael Hudson mwh21 at cam.ac.uk
Mon Apr 3 01:24:01 CEST 2000


lewst <lewst at yahoo.com> writes:

> Fredrik Lundh <effbot at telia.com> 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.

I'm afraid that doesn't help (me, at least).  It still sounds like
you're trying to write tcl or perl in Python.  What problem are you
trying to solve (at a higher level)?  It's likely that there is a
reasonable elegant way of doing it in Python, but it's unlikely to
look much like what a solution would look like in another langauge.

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

I'd say so.  Here you could type:

mydict = { ".":[], "+":[] }

but I'd guess that's of no help.

Hoping to help,
M.

-- 
well, take it from an old hand: the only reason it would be easier
to program in C is that you can't easily express complex  problems
in C, so you don't.                 -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list