[Zope] creating a python function callable within zope

peter sabaini sabaini@inode.at
Fri, 02 Aug 2002 23:19:08 +0200


i dont know how useful this would be, but theoretically you should be 
able to put a function into the misc_ dictionary of your product

usually you use the misc_ dictionary for images, eg.

misc_ = { 'logo' : Globals.ImageFile( ... ) }
(this goes into your products __init__.py)

which then can be called with an url

/misc_/YourProductName/logo

so you could do something like

def func():
   # ...
misc_ = { 'func' : func }


but i dont know if it would get passed any url parameters etc., and i 
think you wont have access to acquisition

is there some specific reason not to make your function a class method?

  - peter.



Steve Nicholson wrote:
> I have created a python based zope product for the cmf which is working
> ok. I would like to create a function that belongs in the same .py file
> as the product class but the function will not be a method of a class
> instance. I want to be able to call this function from anywher within
> zope to do something related to the product class but not an instance of
> that class. I assume the function "def function( self ): etc..." is
> placed outside of the class statement in the .py file but I cannot work
> out what I need to do to be able to call it in zope, or if it's possible
> or wise to do. At the moment I have this function written in a zope
> "python script". Or am I supposed to make it an external method?
> 
> Hope that makes sense as I'm still trying to get my head around this
> class,instance,method,function thing!
> Any ideas or help on where I am going wrong would be much appreciated.
> 
> (Running zope 2.5.1 / python 2.1.3 / win2000)
> Thanks
> Steve.
> 
> 
> _______________________________________________
> 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 )
> 
>