1.11M Members

Positional arguments in a __getattr__ wrapper?

 
0
 

Hi guys,

I have a code that intercepts calls to methods via getattr. Something like:

def __getattr__(self, attr, *fcnargs, **fcnkwargs):
    out=getattr(self._df, attr)(*fcnargs, **fcnkwargs)
    etc...

My goal is when a user calls a method, if it is not a method of self, the program attempts to run it on one of the objects in my class. Eg if there is no method self.foo(), it runs self.x.foo().

This works fine; however, I just realized that this cannot pass positional arguments into the getattr fcn. For example, if my method requires two positional arguments, call them "foo1, foo2", then I am not able to get the required behavior. Eg, I would need something like:

def __getattr__(self, attr, foo1, foo2 *fcnargs, **fcnkwargs):
    out=getattr(self._df, attr)(foo1, foo2, *fcnargs, **fcnkwargs)
    etc...

Of course, this behavior is not what I want. I had expected positional arguments to show up in the fcnargs variable, but they seem not to! Can anyone help with this?

Thanks.

 
0
 

Sorry, this appears to be some sort of bug in code and not the way python behaves in general.

Question Self-Answered as of 1 Year Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article