How to let python function pass more variables than what's accepted in the definition? -


i have generic function call looks like

result = getattr(class_name, func_name)(result) 

this function call updates result. function call generic such can invoke many functions different classes. currently, these functions take 1 argument result. however, doesn't scale cases functions need pass more result more arguments (say, args).

is there way in python (2.7) allows generic function call pass args still invoke functions don't have arguments? if not, better approach solve problem?

edit: cannot change existing function definitions, including take argument result. can change line:

result = getattr(class_name, func_name)(result) 

you can add * within function call. pass result multiple arguments. lets have 2 functions:

class yourclass:    def my_first_def(one_arg):       return (1, 2)     def my_second_def(one_arg, second_arg):       return (1, 2, 3)   if not instanceof(result, tuple):   result = (result,)  result = getattr(yourclass, 'my_first_def')(*result) result = getattr(yourclass, 'my_second_def')(*result) 

do note result must tuple


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -