Re: [Zope] How do I eval a variable within the acquisition path?
This is what I was looking for. Thanks to all. Tim > print context.Vet[category][animal].vaccinateplan() > > cheers, > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > - http://www.simplistix.co.uk > ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How do I eval a variable within the acquisition path?
Tim Nash wrote: category = REQUEST.form['category'] animal = REQUEST.form['animal'] print context.Vet.category.animal.vaccinateplan() print context.Vet[category][animal].vaccinateplan() cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How do I eval a variable within the acquisition path?
Tim Nash schrieb: > I apologize for the question (the zope area of my brain must need > coffee) but I can't find the answer in the zope book or in any of the > scripts posted to the zope cookbook. > > I want to use a variable in a acquisition path. > > So for example, from the zope book on scripts, imagine that > vaccinateplan() printed out a specific animals vaccination plan. > > Now instead of saying 'LargeAnimals' and 'hippo' like so: > > print context.Vet.LargeAnimals.hippo.vaccinateplan() > > I want to do like this: > > category = REQUEST.form['category'] > animal = REQUEST.form['animal'] > > print context.Vet.category.animal.vaccinateplan() print context.Vet[category] or print getattr(context.Vet, category, 'some default value') hth robert begin:vcard fn:Robert Rottermann n: Rottermann;Robert email;internet:[EMAIL PROTECTED] tel;work:++41 31 333 10 20 tel;fax:++41 31 333 10 23 tel;home:++41 31 333 36 03 x-mozilla-html:FALSE version:2.1 end:vcard ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How do I eval a variable within the acquisition path?
- Original Message - From: "Tim Nash" <[EMAIL PROTECTED]> To: "Jonathan" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, August 21, 2007 9:10 PM Subject: Re: [Zope] How do I eval a variable within the acquisition path? Thank you, that is cool but it isn't what I was looking for. My fault. It is hard to describe. This may be called an indirect variable reference. I want the form to ask for the type of animal (hippo? giraffe?) and send it to a python script. No problem here. I can write the form and most of the script that is called. But this is where I have the problem. The python script will use the name of the animal to go down into the proper folder and call vaccinateplan() on all the items in that folder. The key line in the python script is: print context.Vet.category.animal.vaccinateplan() That runs the vaccinateplan script on the folder which has a folder id of either 'hippo' or 'girafee'. And it is in the folder named by the variable category and in the folder named 'Vet' There is no folder with the id of 'category' or 'animal' I'm sorry my explanations are not clear. And I shouldn't have used the hippo and girafee example from the zope book because that is doing something a little different. Below is the directory structure I am thinking of. Thanks! Tim vet | largeAnimal | | |hippo |girafee |---small Animal | |--vacinateplan() If you are dealing with a form then you could just direct the 'action' to point to the 'vacinateplan' script, then use REQUEST['animal'] or REQUEST.form['animal'] Alternatively... if u restructure your URLs so that they look like: www.xyz.com/vacinateplan/hippo or www.xyz.com/vacinateplan/giraffe etc Then you can set up your python script ("vacinateplan") to access the 'animal' variable as follows: print traverse_subpath[0] It is also possible that i am unclear on your use case! Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How do I eval a variable within the acquisition path?
Thank you, that is cool but it isn't what I was looking for. My fault. It is hard to describe. This may be called an indirect variable reference. I want the form to ask for the type of animal (hippo? giraffe?) and send it to a python script. No problem here. I can write the form and most of the script that is called. But this is where I have the problem. The python script will use the name of the animal to go down into the proper folder and call vaccinateplan() on all the items in that folder. The key line in the python script is: print context.Vet.category.animal.vaccinateplan() That runs the vaccinateplan script on the folder which has a folder id of either 'hippo' or 'girafee'. And it is in the folder named by the variable category and in the folder named 'Vet' There is no folder with the id of 'category' or 'animal' I'm sorry my explanations are not clear. And I shouldn't have used the hippo and girafee example from the zope book because that is doing something a little different. Below is the directory structure I am thinking of. Thanks! Tim vet | largeAnimal | | |hippo |girafee |---small Animal | |--vacinateplan() On 8/21/07, Jonathan <[EMAIL PROTECTED]> wrote: > > - Original Message - > From: "Tim Nash" <[EMAIL PROTECTED]> > To: > Sent: Tuesday, August 21, 2007 7:17 PM > Subject: [Zope] How do I eval a variable within the acquisition path? > > > >I apologize for the question (the zope area of my brain must need > > coffee) but I can't find the answer in the zope book or in any of the > > scripts posted to the zope cookbook. > > > > I want to use a variable in a acquisition path. > > > > So for example, from the zope book on scripts, imagine that > > vaccinateplan() printed out a specific animals vaccination plan. > > > > Now instead of saying 'LargeAnimals' and 'hippo' like so: > > > > print context.Vet.LargeAnimals.hippo.vaccinateplan() > > > > I want to do like this: > > > > category = REQUEST.form['category'] > > animal = REQUEST.form['animal'] > > > > print context.Vet.category.animal.vaccinateplan() > > > > > > > > but I get an Attribute Error. How do I eval a variable within the > > acquisition path? > > any items in a url after python script name will be placed into REQUEST. > Example: > > if there is a python script called 'ptst' in the folder 'folderx' > then the url: www.xyz.com/folderx/ptst/a/b/c > will result in the python script "ptst" being run and the following entry > will be in REQUEST: > traverse_subpath ['a', 'b', 'c'] > > hth > > Jonathan > > ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How do I eval a variable within the acquisition path?
- Original Message - From: "Tim Nash" <[EMAIL PROTECTED]> To: Sent: Tuesday, August 21, 2007 7:17 PM Subject: [Zope] How do I eval a variable within the acquisition path? I apologize for the question (the zope area of my brain must need coffee) but I can't find the answer in the zope book or in any of the scripts posted to the zope cookbook. I want to use a variable in a acquisition path. So for example, from the zope book on scripts, imagine that vaccinateplan() printed out a specific animals vaccination plan. Now instead of saying 'LargeAnimals' and 'hippo' like so: print context.Vet.LargeAnimals.hippo.vaccinateplan() I want to do like this: category = REQUEST.form['category'] animal = REQUEST.form['animal'] print context.Vet.category.animal.vaccinateplan() but I get an Attribute Error. How do I eval a variable within the acquisition path? any items in a url after python script name will be placed into REQUEST. Example: if there is a python script called 'ptst' in the folder 'folderx' then the url: www.xyz.com/folderx/ptst/a/b/c will result in the python script "ptst" being run and the following entry will be in REQUEST: traverse_subpath ['a', 'b', 'c'] hth Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] How do I eval a variable within the acquisition path?
I apologize for the question (the zope area of my brain must need coffee) but I can't find the answer in the zope book or in any of the scripts posted to the zope cookbook. I want to use a variable in a acquisition path. So for example, from the zope book on scripts, imagine that vaccinateplan() printed out a specific animals vaccination plan. Now instead of saying 'LargeAnimals' and 'hippo' like so: print context.Vet.LargeAnimals.hippo.vaccinateplan() I want to do like this: category = REQUEST.form['category'] animal = REQUEST.form['animal'] print context.Vet.category.animal.vaccinateplan() but I get an Attribute Error. How do I eval a variable within the acquisition path? Thanks, Tim ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )