How to let python function pass more variables than what's accepted in the definition?
<p>I have a very generic function call that looks like</p>

<pre><code>result = getattr(class_name, func_name)(result)
</code></pre>

<p>This function call updates <code>result</code>. This function call is very generic such that it can invoke many functions from different classes. Currently, all these functions only take one argument <code>result</code>. However, it doesn't scale to the cases that some functions need to pass more than just <code>result</code> but more arguments (say, <code>args</code>).</p>

<p>Is there a way in Python (2.7) that allows this generic function call to pass <code>args</code> but still invoke the functions that don't have the extra arguments? If not, what would be a better approach to solve this problem?</p>

<p>EDIT: I cannot change the existing function definitions, including those that only take only the argument <code>result</code>. I can only change this line:</p>

<pre><code>result = getattr(class_name, func_name)(result)
</code></pre>

<p>The general solution for this is that when we want to provide a common function name such as this, that it is the responsibility of each class to implement its local definition of that function.  This is why you see, for example, a method <strong>__init__</strong> in many different classes.  The system standardizes the name, placing the requirement on the classes.</p>

<p>The other common way is borrowed from <strong>C</strong>: you pass a list of arguments, the canonical *args solution.  This allows one generic, flexible function to interpret the arglist as appropriate.</p>

python python-2.7