Python - how to handle outcome variables that are conditional set correctly
<p>Consider the following:</p>

<pre><code>    def funcA():
        some process = dynamicVar
        if dynamicVar == 1:
            return dynamicVar
        else:
            print "no dynamicVar"

    def main():
        outcome = funcA()
</code></pre>

<p>If the 'some process' part results in a 1, the var dynamicVar is passed back as <code>outcome</code> to the main func. If dynamicVar is anything but 1, the routine fails as no arguments are being return. </p>

<p>I could wrap the outcome as a list:</p>

<pre><code>    def funcA():
        outcomeList = []
        some process = dynamicVar
        if dynamicVar == 1:
            outcomeList.append(dynamicVar)
            return outcomeList
        else:
            print "no dynamicVar"
            return outcomeList

    def main():
        outcome = funcA()
        if outcome != []:
            do something using dynamicVar
        else:
            do something else!
</code></pre>

<p>or maybe as a dictionary item. Each of the 2 solutions I can think of involve another set of processing in the main / requesting func. </p>

<p>Is this the 'correct' way to handle this eventuality? or is there a better way? </p>

<p>What is the proper way of dealing with this. I was particularly thinking about trying to catch <code>try:</code> / <code>except:</code> errors, so in that example the uses are reversed, so something along the lines of:</p>

<pre><code>    def funcA():
        some process = dynamicVar
        if dynamicVar == 1:
            return
        else:
            outcome = "no dynamicVar"
            return outcome 

    def main():
        try:
            funcA()
        except:
            outcome = funcA.dynamicVar 
</code></pre>
