NEW TO THIS: Assigning values to strings in list?

Chris Liechti cliechti at gmx.net
Fri Jul 19 14:30:09 EDT 2002


Johannes Graumann <graumann at clyde.caltech.edu> wrote in
news:ah9kgo$5k9 at gap.cco.caltech.edu: 
> Chris Liechti <cliechti at gmx.net> wrote:
>> Johannes Graumann <graumann at clyde.caltech.edu> wrote in 
>>>>names = ["one","two","three"]
>>>>values = [ 1,2,3]
> --> DO SOMETHING HERE
>>>>print one
> 1

my tip: don't pollute the global namespace.
if you do it with a class it's easier anyway:

>>> class Lexikon:
... 	def __init__(self, values):
... 		self.__dict__.update(values)
... 	
>>> l = Lexikon(dict(zip(names,values)))
>>> l.one
1

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list