Getting an object indirectly in a PythonMethod
I have a python method as part of a ZClass. I want this method to return an object whose id is stored in a ZClass property. In DTML this would be as simple as <dtml-return "_[ObjNameProperty]"> I can't figure out how to do this in a python method. Things such as self.getattr(ObjNameProperty) don't seem to work at all.
"Jay, Dylan" wrote:
I have a python method as part of a ZClass. I want this method to return an object whose id is stored in a ZClass property. In DTML this would be as simple as <dtml-return "_[ObjNameProperty]"> I can't figure out how to do this in a python method. Things such as self.getattr(ObjNameProperty) don't seem to work at all.
try getattr(self,ObjNameProperty) , it has workwed forr me (once ;) ------ Hannu
Hannu Krosing wrote:
"Jay, Dylan" wrote:
I have a python method as part of a ZClass. I want this method to return an object whose id is stored in a ZClass property. In DTML this would be as simple as <dtml-return "_[ObjNameProperty]"> I can't figure out how to do this in a python method. Things such as self.getattr(ObjNameProperty) don't seem to work at all.
try getattr(self,ObjNameProperty) , it has workwed forr me (once ;)
'return getattr(self, ObjNameProperty) ' will indeed return the named attribute. Be aware, though, that this is equivalent to <dtml-return "_.getitem(ObjNameProperty,0)"> and *not* quite the same as <dtml-return "_[ObjNameProperty]">. The second form does magic namespace rendering of the object, and would look something like 'return getattr(self, ObjNamePropertry)(self, REQUEST)'. Evan @ 4-am
participants (3)
-
Evan Simpson -
Hannu Krosing -
Jay, Dylan