Making variable from a variable
anton muhin
antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru
Thu Oct 9 06:18:38 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
And kust my 2 cents (a safer way):
>>> class NS(object): pass
...
>>> ns = NS()
>>> ns.foo = "bar"
>>> setattr(ns, ns.foo, "foobar")
>>> print ns.foo, ns.bar
bar foobar
>>>
More information about the Python-list
mailing list