Get attributes from a returned function in Python
<pre><code>def outerFunc(number):
    if number &lt; 0:
        def innerFunc(factor):
            return number * factor
    else:
        def innerFunc(summand):
            return number + summand
    return innerFunc

x = outerFunc(-8)
print(x(4))
</code></pre>

<p>The result of the print statement is <code>-32</code>, as expected. I'm using Python 3.5.2</p>

<p>I would like to ask two questions regarding this code snippet:</p>

<ol>
<li>Is it possible to access the inner function's <code>number</code> property, after having bound <code>innerFunc</code> to <code>x</code> with the statement <code>x = outerFunc(-8)</code>? In other words: is it possible to directly access the preserved value of <code>number</code>, in this case <code>-8</code>, after having performed the closure?</li>
<li>Is it good programming style to return a function, depending on the evaluation of an if-statement? Personally, I think there is better approach, but I'm not sure.</li>
</ol>

<p>Thanks for your help.</p>

<ol>
<li>No.</li>
<li>Rarely, but there are cases where it could make sense. If you have to ask the question, you should probably consider the answer to be 'no,' at least for now.</li>
</ol>

python closures