[Zope] 'helper' classes in External Methods
Pavlos Christoforou
pavlos@gaaros.com
Fri, 3 Mar 2000 15:00:00 -0500 (EST)
On Fri, 3 Mar 2000, Tony McDonald wrote:
> This is an example from an external method that Pavlos posted a while back.
>
> class MCQ:
> ''' helper class for MCQ system'''
> def __init__(self, score):
> ''' constructor'''
> self.score = 0
> self.total_score = 0
>
I think it is not a good idea to define classes in external methods. It is
better to define them somewhere in Shared (see the directory DC under
lib/python/Shared for example) and import them in your external method.
import Shared.Tony.helper
They can be very handy especially since python is way more elegant and
easy for complex logic in relation to DTML.
> What I would like to do is load up a template_lookups dictionary with
> quite a few entries;
>
> for template_id in self.Actors.RENDER.objectIds():
> renderer = eval("self.Actors.RENDER.%s" % template_id)
> template_lookups[template_id] = renderer
>
> Thing is, I need access to the ZODB in one of my methods later in the
> module and so the above code doesn't work (too many 'selfs'!).
>
> Anyone got any ideas?
Not sure. need some more info. Did you try to use getattr to get to
object?
tmp=self.Actors.RENDER
renderer=getattr(tmp,template_id)
What kind of object is template_id?
Pavlos