Do-it-yourself acquisition -- is there an easier way?
Hello, I have python products and python scripts in which I am trying to get a certain object, by id, from higher up in the acquisition chain. I know that this object is in a folder named 'toolbox', so the code I have is as follows: def get_foo(self, fooID): default_foo = None for parentObj in self.aq_chain: try: toolbox = parentObj._getOb('toolbox') foo = toolbox._getOb(fooID) return foo except: continue return default_foo This works, but seems very clunky. Is there an API call that is cleaner? Does the method above have a hidden danger or difficulty that I am not seeing? Thanks, VanL
VanL wrote:
Hello,
I have python products and python scripts in which I am trying to get a certain object, by id, from higher up in the acquisition chain.
I know that this object is in a folder named 'toolbox', so the code I have is as follows:
def get_foo(self, fooID): default_foo = None for parentObj in self.aq_chain: try: toolbox = parentObj._getOb('toolbox') foo = toolbox._getOb(fooID) return foo except: continue return default_foo
urm, does the following code do the same as the above? def get_foo(self,fooID): return getattr(self.toolbox,fooID,None) cheers, Chris
VanL writes:
I have python products and python scripts in which I am trying to get a certain object, by id, from higher up in the acquisition chain.
I know that this object is in a folder named 'toolbox', so the code I have is as follows:
def get_foo(self, fooID): default_foo = None for parentObj in self.aq_chain: try: toolbox = parentObj._getOb('toolbox') foo = toolbox._getOb(fooID) return foo except: continue return default_foo
This works, but seems very clunky. Is there an API call that is cleaner? Does the method above have a hidden danger or difficulty that I am not seeing? Hell! Do you know "[un]restrictedTraverse"?
Dieter
participants (3)
-
Chris Withers -
Dieter Maurer -
VanL