creating lists question?

Josiah Carlson jcarlson at nospam.uci.edu
Tue Mar 23 22:03:46 EST 2004


> I'm not sure this is doing what I want it to do. In the example I gave I
> want a new list call "aaa" another list called "bbb"... so I can append to
> the new list  i.e., bbb.append().  It may be that your example does this but
> it appears to be (with my limited knowledge) that it's creating a list of
> lists, when all I want is a new isolated list.

Matt already gave an answer for how to do it using exec.  There is 
another method:

for name in list1:
     locals()[name] = []

The above gets the dictionary for the local namespace, and makes the 
name given point to a new list.

This doesn't have the same security holes as exec, but may have 
(non-exploitable) security holes, eg lists with builtin or module names.

  - Josiah



More information about the Python-list mailing list