Variable Variable

Kay Schluehr kay.schluehr at gmx.net
Sat Mar 19 11:46:41 CET 2005


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




More information about the Python-list mailing list