From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Philip Kilner
I'm having problems with testing for the existence of a key in my request. I've had similar problems in the past, and asked the list in the past, but always managed to fumble my way out of them - now I seem to be 100% stuck!
I'm working on a page template which calls a python script. This script needs to: -
- Test for the existence of a counter called "job_step". - If it does not exist, initialise it as one (it's an integer). - If it does exist, perform conditional tasks based on it's value.
My script reads, in part: -
req = context.REQUEST
if req.has_key('job_step'):
if req.job_step == 1: do that...
...and that's where my problem lies - the test /always/ fails!
_Which_ test fails? 1) if req.has-key(), or 2) if req.job_step == 1 If the latter, you are getting the form data as a string, and you have to convert it into an integer to get what you want. Cheers, Tom P
Hi Tom, Passin, Tom wrote:
req = context.REQUEST
if req.has_key('job_step'):
if req.job_step == 1: do that...
...[snip]...
_Which_ test fails?
1) if req.has-key(), or
Yup, the test for the existence of the key is the one I'm stuck on...
2) if req.job_step == 1
If the latter, you are getting the form data as a string, and you have to convert it into an integer to get what you want.
...although when I have bodged my script to bypass this test, I have indeed hit the problem you suggest. Fortunately, my dog-eared copy of "Learning Python" (You'd think anyone who could so batter a book would have picked up more...) got me out of that one! Ta! Any clue about the if req.has_key('job_step') line? Cheers, PhilK
participants (2)
-
Passin, Tom -
Philip Kilner