[Zope] python ignorance shining through...

Phil Harris phil@philh.org
Tue, 14 Sep 1999 13:09:22 +0100


Hi tone

If I understand correctly you want to get the contents of an object but you
only have the name and not a reference to it, correct?

If that is the case then try this:

try:
   template_str = eval("self.RENDER.%s.read_raw()" % tagclass)
   template = DocumentTemplate.HTML(template_str)
   theresult = template(self, content=content)
   return theresult
except KeyError:
   return "no renderer for %s" % tagclass

The eval will take a string and evaluate it in the current context, this
should use the contents of tagclass to create a callable reference to that
tagclass object.

HTH

Phil
phil@philh.org



----- Original Message -----
From: Tony McDonald <tony.mcdonald@ncl.ac.uk>
To: Zope List <zope@zope.org>
Sent: Tuesday, September 14, 1999 12:33 PM
Subject: [Zope] python ignorance shining through...


> Hi all,
> I've got an external method that does an SQL lookup and retrieves
> (essentially) two fields, tagclass and content.
> What I'm doing at the moment is;
>
> if tagclass == 'modulecontributor':
>    template_str = self.RENDER.modulecontributor.read_raw()
>    template = DocumentTemplate.HTML(template_str)
>    theresult = template(self, content=content)
>    return theresult
>
> How can I do something like;
>
> try:
>    template_str = self.RENDER.(the contents of tagclass).read_raw()
>    template = DocumentTemplate.HTML(template_str)
>    theresult = template(self, content=content)
>    return theresult
> except KeyError:
>    return "no renderer for %s" % tagclass
>
> any pointers gratefully received..
> tone
>
> ------
> Dr Tony McDonald,  FMCC, Networked Learning Environments Project
> http://nle.ncl.ac.uk/
> The Medical School, Newcastle University Tel: +44 191 222 5888
> Fingerprint: 3450 876D FA41 B926 D3DD  F8C3 F2D0 C3B9 8B38 18A2
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (To receive general Zope announcements, see:
> http://www.zope.org/mailman/listinfo/zope-announce
>
> For developer-specific issues, zope-dev@zope.org -
> http://www.zope.org/mailman/listinfo/zope-dev )
>