We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Positional arguments in a __getattr__ wrapper?

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.

1
Contributor
1
Reply
3 Hours
Discussion Span
3 Months Ago
Last Updated
2
Views
Question
Answered
dashing.adamhughes
Newbie Poster
20 posts since Nov 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0

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

dashing.adamhughes
Newbie Poster
20 posts since Nov 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0
Question Self-Answered as of 3 Months Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.2772 seconds using 2.64MB