[Tutor] creating variable names from string slices

Michael Janssen Janssen@rz.uni-frankfurt.de
Tue Apr 1 05:16:02 2003

On Tue, 1 Apr 2003, noc wrote:

> How do i make this trick work?

simply forget such tricks! Do not stuff arbitrary data into your global
namespace (Or what will you do, when one of those pretties are called
"str" or "SystemExit"? ;-)

E.g. you can put it into a list (or a dictionary of dictionaries or
whatever suits your purpose best):

data = [{'name':'Betty', 'haircolor':'Blonde', 'role':'Student'},
         {'name': 'Veron', 'haircolor':'Brunett', 'role':'Student'},
         {'name': 'Ginge', 'haircolor':'Redhea', 'role':'Castawa'},
         {'name': 'Marya', 'haircolor':'Brunett', 'role':'Castawa'},