Variable Variable

Cameron Laird claird at lairds.us
Sat Mar 19 07:08:03 EST 2005


In article <1111229201.840663.141530 at g14g2000cwa.googlegroups.com>,
Kay Schluehr <kay.schluehr at gmx.net> wrote:
>
>Tanteauguri wrote:
>> Hi List, is there in python a variable variable like in PHP ($$var)?
>>
>> What I want to do is something like that:
>>
>> pc=["a","b","c"]
>>
>> for i in pc:
>> 	i = anyclass()
>>
>> a.shutdown()
>> b.update()
>>
>>
>> Any Ideas?
>
>def seq(n,cls,*args,**kw):
>    "create a sequence of n objects of type cls."
>    return [cls(*args,**kw) for i in range(n)]
>
>>>> a,b,c = seq(3,anyclass)
>>>> a.shutdown()
>>>> b.update()
>
>Regards Kay
>

I'm going to make this explicit:  the PHP idiom is a defect.
Yes, I know that's good style among top PHP practitioners, 
but, from all I know, it's simply a bad habit.  The advice to
use a dictionary is on target.



More information about the Python-list mailing list