lists of variables

Jonathan Gardner jgardner at jonathangardner.net
Sun Feb 21 00:25:37 EST 2010


On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
<python-list at open-sense.com> wrote:
>
> But what would be "the python way" to accomplish "list of variables"
> functionality?
>

You're looking for namespaces, AKA dicts.

>>> vars = {}
>>> vars['a'] = 1
>>> vars['b'] = 2
>>> mylist = ['a', 'b']
>>> print [vars[i] for i in mylist] # Here's your dereference
[1,2]
>>> vars['a'] = 3
>>> print [vars[i] for i in mylist]
[3,2]


-- 
Jonathan Gardner
jgardner at jonathangardner.net



More information about the Python-list mailing list