python getattr built-in method executes default arguments
<p>I dont know if this is something an expected behavior of <code>getattr</code> built_in method.
<code>getattr</code> executes the default(3rd) argument as well even if the actual argument(2nd) satisfies the condition.
Example:</p>

<pre><code>def func():
    print('In Function')

class A:
    def __init__(self):
        self.param = 12

a = A()
</code></pre>

<p>When I run <code>getattr(a, 'param', func())</code> it gives this result:</p>

<pre><code>In Function
12
</code></pre>

<p>Note the <code>In Function</code> which I don't want.</p>

<p>But it works perfectly fine when I execute <code>getattr(a, 'param1', func())</code> i.e output</p>

<pre><code>In Function
</code></pre>

<p>But I only want result as <code>12</code> if satisfied the condition. Please let me know why <code>getattr</code> has such behaviour and can we stop them of doing it (that is not to execute 3rd arg if has 2nd argument), would be appreciated if share the alternate way of doing it in Pythonic way.
One thing that comes in mind first is to check if <code>param1</code> exist using <code>hasattr</code> and then do the needful.</p>