Go to your python script and click on the bindings tab. The fourth item has a heading of Namespace. Put the recommended value of _ into the field and save changes. What this does is it binds the namespace that is available to dtml-methods normally to the name _. The problem you were running into is that when you enter a python script, normally this namespace *IS NOT* passed into the script. But, once you bind it to the _ name, you can access it by doing things like _.getitem('') or _.has_key('') etc. The last piece of the puzzle is to pass that namespace into your dtml method so it can access it by passing it as the second parameter. Notice that you can set it to whatever name you want. I think there are historical reasons why it has generally been _. If you do set it to something else, then you need to change _ to your new name in your code. This was one of the biggest frustrations I had and still sometimes have with moving to more python scripted code. Writing python scripts is a lot easier for complex logic. But the namespace stuff seems unnecessarily complex and frustrating sometimes. There is probably an easier way to do this sort of thing and perhaps someone with more experience would like to comment and clarify, but this is how I was able to get my code working. Good Luck, -Chris ------------------------------ Chris Kratz chris.kratz@vistashare.com ----- Original Message ----- From: Shane O'Sullivan To: Chris Kratz ; zope@zope.org Sent: Tuesday, October 30, 2001 12:04 PM Subject: Re: [Zope] calling dtmlMethod from python Chris, thanks for your help...I tried your suggestion but it has now returned the error Error Type: NameError Error Value: global name '_' is not defined If you have time, would you mind explaining what "_" represents? Is this defined in a library that we mightn't have included? Thanks again, Shaneo ----- Original Message ----- From: Chris Kratz To: Shane O'Sullivan ; zope@zope.org Sent: Tuesday, October 30, 2001 4:26 PM Subject: Re: [Zope] calling dtmlMethod from python I ran into this awhile back. Try this: context.scReport(None, _) Interestingly enough, I also learned that you can pass things into a dtml-method and they become available to use internally. For example with the following call: context.scReport(None, _, MsgToUser='Hello') Inside your dtml-method you could do a <dtml-var MsgToUser> This is very usefull to passing stuff around without cluttering up your REQUEST namespace. Another little trick I learned. Want to find an object via acquisition and then call it? I found that the following worked in a python script: methodToCall = _.getitem('methodName') # Find object via acquisition and get handle on it. print methodToCall(None, _) # Call the method and print the results. This is really usefull if you generate the method name as I do depending on the request. ie methodToCall = _.getitem(someStrVar + 'form') will concatenate the two strings and then look for that object in the namespace. If you do this kind of lookups, you should probably also check for existence before calling it, ie _.has_key(someStrVar + 'form'). Hope that helps. -Chris ------------------------------ Chris Kratz chris.kratz@vistashare.com ----- Original Message ----- From: Shane O'Sullivan To: zope@zope.org Sent: Tuesday, October 30, 2001 11:13 AM Subject: [Zope] calling dtmlMethod from python Can anyone please help with this, I'm new to zope and trying to write a simple python script to handle some logic which will then call a dtml method. I'm calling the method as such: context.scReport() The error I'm getting back is Error Type: KeyError Error Value: standard_html_header standard_html_header is being called from the scReport method which suggests the scReport method is being invoked but why are we getting an error?? Any suggestions, TIA Shaneo