missing methods or __getattr__ problem
Uwe C. Schroeder
uwe at oss4u.com
Wed Oct 2 20:14:06 CEST 2002
I'm a little stuck here and my brain turns in circles.
Here's what I'm trying to accomplish and I'm sure there is a very
simple solution to this problem:
The caller calles a method xx.callme(objecttype, parameters)
The called object keeps a list of class instances where the
paricularly wanted object can be found via the "objecttype"
parameter. However the called object itself doesn't have the called
attribute. What I'm looking for is a way to transparently call a
method as if it was part of the called object. So the called object
has to do the following:
1. figure out if the called attribute is a member of itself
2. if not 1. take the first parameter and look up the object in
which the wanted method resides
3. call the (hopefully found) method and return the results.
Using __getattr__ makes no sense since I need the parameters not
only the name. Using __call__ and have __getattr__ redirect to
__call__ won't work either since __call__ then has the paramters,
but not the method name.
How to do this ?
Here's some code example:
OBJ_PROGRAM = 5999
# Objects is a class that keeps the references
# to instances of other objects containing
# the methods to call. It's much like a dict
# This would be OK if I made a wrapper method for
# each method to be called
print bng.getAllPrograms() # works fine
print bng.getAll(OBJ_PROGRAM) # how to do this ?
Point is, that the final app will have hundreds of methods
to be called. The calls come in via XML-RPC and are all mapped to
the bng class instance. If I set up a wrapper for each method to be
called the bng class will be HUGE and hard to maintain.
Any help is appreciated.
More information about the Python-list