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. ***********************************************************************
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 )
On 4/3/02 5:55 am, "Robert Rottermann" <robert@redcor.ch> wrote:
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!
Robert is right - External Methods can do *almost* anything. It looks like you create variables from a form, specify1, specify2 ... specifyn And you want to get the value of those variables (they're not really python expressions like '3*x + 4' are they? In that case you will need an External Method. If the values are something like 'fish', 'leg', 'foot', then this should do it. <dtml-var "REQUEST['specify1']"> ... <dtml-var "REQUEST['specifyn']"> If you want to do this programmaticaly, (untested! :) your_list = ['specify1', 'specify2' ...] <dtml-in your_list> <dtml-var "REQUEST[_['sequence-item']]"> </dtml-var> (I tested this code, and it picks up the URL0, URL1 and URL2 variables). <dtml-let urllist="['0', '1', '2']"> <dtml-in urllist> <dtml-var sequence-item> <dtml-var "REQUEST['URL' + _['sequence-item']]"><br> </dtml-in> </dtml-let> This is easier to do in python though (pass my_list as parameter) (again, untested, and no checks to make sure those variables *do* exist) request=context.REQUEST for a_var in my_list: print request[a_var] return printed hth Tone -- Dr Tony McDonald, Assistant Director, FMCC, http://www.fmcc.org.uk/ The Medical School, Newcastle University Tel: +44 191 243 6140 A Zope list for UK HE/FE http://www.fmcc.org.uk/mailman/listinfo/zope
From: "Greg Conway" <greg@gmlnt.com>
I'm managing (very slowly!) to ease myself from DTML to Python, but I have just hit a bit of a snag...
Now, are you talking python scripts or python products? There are differencies...
What I've done is stored these values within a form using a loop
Store where?
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!
That *is* programatically.
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!
Why do you have single quotes around REQUEST.specify? That turns it into a string, you know...
What I really want to do is (I think)...
TestVar = eval("REQUEST.specify" + str(OutsideLoop.CatID))
No it isn't, what you want to do it to get rid of the quotes. And you may want to try REQUEST['specify'] instead. I'm not sure what type REQUEST is in pythonscripts but in normal python it is a dictionary. You might also want to look at using parameters instead of chugging everything into REQUEST.
participants (4)
-
Greg Conway -
Lennart Regebro -
Robert Rottermann -
Tony McDonald