Newbie External Method - Python help
Hi all, I am trying to process some operations in a external method, becuase as far as i know, i can't import mysqldb in a python script due to security restrictions. Through a form I get the values of the variables and the action of the form is the execution of the external method. The external method starts comparing a value, so if it is equal to 'c' for example, other function starts and so on. The problem I have is that I would need to set the values of the form variables as global, so any function inside the external method can access to them. As I explicitly need to place a function name in Zope's external method manage screen, I don't know how to set these variables as global. Any help will be apreciated TIA Vicente Castelló
I have never had a need to make the form variables "global" and I don't think you need to either. Just pass the variables you need as parameters to the external method - or, better, just pass REQUEST as a parameter. If your external method calls other functions, let it get the form data from REQUEST and pass it to them. That is, if your external method is called spam(), you would use something like <dtml-var "spam(REQUEST)"> Cheers, Tom P [Vicente Castelló Ferrer] I am trying to process some operations in a external method, becuase as far as i know, i can't import mysqldb in a python script due to security restrictions. Through a form I get the values of the variables and the action of the form is the execution of the external method. The external method starts comparing a value, so if it is equal to 'c' for example, other function starts and so on. The problem I have is that I would need to set the values of the form variables as global, so any function inside the external method can access to them. As I explicitly need to place a function name in Zope's external method manage screen, I don't know how to set these variables as global.
=?iso-8859-1?Q?Vicente_Castell=F3_Ferrer?= writes:
... global variables in External Method ... You can try Python's "global" directive:
def fun(...): global x ... x= ... The "global" directive tells Python that the variables belong to the module's namespace (and not the functions one). Be careful, however: In earlier Zope versions, at least until Zope 2.2, probably longer, the source files of External Methods have not been Python modules. Its variables have been thread local. This means, that different requests could see different values. I think, in Zope 2.4 and above, the files are standard Python modules but I am not sure. Dieter
participants (3)
-
Dieter Maurer -
Thomas B. Passin -
Vicente Castelló Ferrer