[Zope] Totaly dynamic path?

Dieter Maurer dieter@handshake.de
Fri, 5 Jul 2002 23:24:23 +0200


Roger writes:
 > ...
 > how can I construct a dynamic path like:
 > getattr(self, 'personManager').getData().addPerson( firstname='max',
 > lastname='miller')
This does not like a path for me...

Okay, lets see:

  *  you already know "getattr". It resolves simple attributes
     given by an expression

  *  you can handle keyword parameters (your "firstname", "lastname")
     via a dictionary and the "apply" method (see Python library
     documentation: built-in function "apply").

  *  the difficult part is "getData().addPerson".
     
     You need to parse this and use "getattr", and "function call"
     to resolve this.

Inside an External Method, you could use "eval" (as an alternative).
But be caseful! Big security risk. You should probably
use some from of "safe_eval" (--> search the archive).


Dieter