Declaring variables from a list

Sidharth Kuruvila sidharth.kuruvila at gmail.com
Fri Apr 8 17:45:01 EDT 2005


Python has a builtin function called locals which returns the local
context as a dictionary

>>> locals = locals()
>>> locals["a"] = 5
>>> a
5
>>> locals["a"] = "changed"
>>> a
'changed'

On 8 Apr 2005 13:55:39 -0700, Cactus <le_cactus at msn.com> wrote:
> Hi,
> 
> If I got a list is it possible to declare a variable from the items in that list?
> 
> Code Sample:
> Blob = ['Var1', 'Var2', 'vAR3']
> i = 5
> for listitems in Blob:
>     i += 1
>     listitems = i
> 
> print Var1
> 6
> print Var2
> 7
> print vAR3
> 8
> 
> Something like that? This doesn't work (obviously) but is there a way to do this?
> 
> TIA,
> Cacti
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
http://blogs.applibase.net/sidharth



More information about the Python-list mailing list