[Zope] evaluating a string as an expression

Robert Rottermann robert@redcor.ch
Mon, 4 Mar 2002 06:55:20 +0100


You can do that in an external method.
(I hope there is a better answer than the on I have to offer tough)

Robert
----- Original Message -----
From: "Greg Conway" <greg@gmlnt.com>
To: "Zope@Zope. Org" <zope@zope.org>
Sent: Monday, March 04, 2002 1:19 AM
Subject: [Zope] evaluating a string as an expression


> Hi all,
>
> I'm managing (very slowly!) to ease myself from DTML to Python, but I have
> just hit a bit of a snag...
>
> I have a string of variables, such as value1, value2, value3, etc.
>
> I wish to find the values of these variables as expressions within python,
> if that makes sense!
>
> What I've done is stored these values within a form using a loop, and now
I
> need to retreive the values in python. I can see them in the request, and
> can access them via REQUEST.specify1, REQUEST.specify2, etc - but not
> programmatically!
>
> After many hours of working through this, I find (I think!) I need the
> python 'eval' command.
>
> And then I find it's not allowed in Zope!!
>
> So my question is (please somebody take pity on me!!), how can I perform
the
> following (pseudo code!!) in python?
>
> TestVar = ( 'REQUEST.specify' + str(OutsideLoop.CatID) )
>
> This doesn't work, obviously! What I really want to do is (I think)...
>
> TestVar = eval("REQUEST.specify" + str(OutsideLoop.CatID))
>
> Please, please, please can anybody offer any help on this?
>
> Regards,
>
> Greg Conway.
>
> --
> +-----------------------------------+
> |  Greg Conway, Technical Director  |
> |    GML Networking Technologies    |
> +-----------------------------------+
>  Email/MSN:    mailto:greg@gmlnt.com
>  ICQ#:                     100219981
>  mobile tel.:   +44 (0) 7974 666 967
>  mobile fax:    +44 (0) 7970 087 935
>  GML support:   +44 (0) 1255 851 999
>  Internet:      http://www.gmlnt.com
>  office tel.:   +44 (0) 1255 672 103
>  office fax:    +44 (0) 1255 679 909
> +-----------------------------------+
> | GMLNT ** Sensible Smart Solutions |
> +-----------------------------------+
>
> ***********************************************************************
> This is a confidential communication between sender and addressee. If you
are not the intended recipient of this message, please notify the sender and
do not read, copy, use or disclose this communication to others. Any
opinions or views expressed are those of the individual, and unless
otherwise stated, are not those of the company. All attachments and
intellectual rights remain the property of GML (NT) Limited.
> ***********************************************************************
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>