When using getattr to obtain a dtml file, etc from a newly formed product, I am able to get the appropriate Zope object and use it. However, I am trying to abstract my class, and when I do, the getattr() function does not work properly. Here's some info: 1) it is not a folderish item 2) the abstract class does not have the need to be managed (ex. Add) 3). Originally I just inherited (for Class 2) from Acquisition.Implicit, figured I could access a persistant member in ZODB, but not even sure if I know what persistance is anymore even after reading some wonderful Tutorials If this all sounds like jibberish, it is.. I'll explain by example Class1 I can use getattr(self, item_id) and it returns item, I guess because the product is actually managed by Zope.. Could someone shed more light on this? I would like to say db_item = Class2(class2 constructors) db_item.process_something(item_id, args) Class2 def process_something(item_id, args) item_to_process=getattr(?, item_id) ? tried self, does not find item_to_process().whatever_the_function(args) Please excuse my dismal attempts.
Johnson, Michael (MIJOHNSO) writes:
... "getattr" does not work for attributes of inherited ZClasses ...
"getattr" does no special things for folderish items. It simply accesses the attributes of an object in case, you can not use the attribute access syntax object.attribute because either the attribute name does not follow Python name syntax or is not constant. Furthermore, it does not care, whether the attribute is defined in the objects class itself or in an inherited class. Thus, "getattr(self,your_attribute)" should work. If not, something else is wrong (there is not attribute with name given be "your_attribute"). Dieter
participants (2)
-
Dieter Maurer -
Johnson, Michael (MIJOHNSO)