Making variable from a variable

Kenneth Zhao ken at epenguin.com
Thu Oct 9 07:11:15 EDT 2003


admin at polerio.com (Polerio Babao Jr.II) wrote in message news:<dcf37d82.0310082219.da7d175 at posting.google.com>...
> I don't know if this question is easy or not but one thing I can say
> is
> I haven't encountered this problem yet in my entire python life. I
> just opened
> this question to the public because I've solved this kind of problem
> already
> before in my PHP life long time ago. I just want to know if it's also
> possible in Python.
> Any idea? Thanks.
> 
> in php
> 
> <?
> 
> $a = 'b';
> ${$a} = 'c';
> print "$a $b";
> 
> ?>
> 
> output is 
> 
> b c

Well, it's simple.  See the following exercise:

bash-2.05b$ python
Python 2.2.3 (#1, Sep 11 2003, 08:34:13)
[GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 'b'
>>> globals()[a] = 'c'
>>> print a, b
b c

-- Ken




More information about the Python-list mailing list