[python] problem s odkazem na promennou

Tomas Brabenec konference na brabenec.net
Čtvrtek Březen 6 11:21:04 CET 2008


Jde to treba pres exec:

promena = "x"
hodnota = "Ahoj svete"
exec("%s=%s" % (promena,hodnota))
print x

TB


Lansky, Milan - Acision napsal(a):
>
> Lze se v Pythonu odkazat na promenou jejiz nazev neni dopredu znam?
>
> Rekneme, jak nastavit promennou var01, kdyz mam k dispozici pouze
>
> retezec ‘var01’?
>
> V bashi se to resi funkci eval:
>
> # nazev_promenne=var01
>
> # eval $nazev_promenne=1
>
> # echo $var01
>
> 1
>
> Dekuji za odpoved.
>
>
> This e-mail and any attachment is for authorised use by the intended 
> recipient(s) only. It may contain proprietary material, confidential 
> information and/or be subject to legal privilege. It should not be 
> copied, disclosed to, retained or used by, any other party. If you are 
> not an intended recipient then please promptly delete this e-mail and 
> any attachment and all copies and inform the sender. Thank you.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Python mailing list
> Python na py.cz
> http://www.py.cz/mailman/listinfo/python


Další informace o konferenci Python