Making variable from a variable
Karl Scalet
news at yebu.de
Thu Oct 9 03:45:17 EDT 2003
Polerio Babao Jr.II wrote:
> 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
not quite as compact:
>>> a='b'
>>> exec("%s='c'"%a)
>>> print a,b
output is
b c
If/why someone want's to do it, is another question.
Karl
More information about the Python-list
mailing list