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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.