[Zope] Re: ZPT: using variables to reference variables

Evan Simpson evan@4-am.com
Fri, 02 May 2003 11:55:58 -0500


martin f krafft wrote:
> how can i use a variable to name another variable before this
> variable gets expanded? e.g.:
> 
>   myvar = 14;
>   a = 'myvar';
>   b = $($a); // b = 14
> 
> is this possible with ZPT and/or python?

It is possible with both.  In a ZPT:

<div tal:define="myvar python:14;
                  a string:myvar;
                  b python:path(a)">

In Python:

myvar = 14
a = 'myvar'
b = locals()[a]

*However*, this will not work in Zope's Python-based Scripts, since they 
do not allow access to locals().

Cheers,

Evan @ 4-am