Author schperplata
Recipients paul.moore, schperplata, steve.dower, tim.golden, zach.ware
Date 2019-03-25.17:31:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I've reported a stack overflow question and no reasonable explation was offered. Here is what I've discovered:
.. code-block:: python
    def func():
        varName = 'bar'
        varValue = 42
        localVarToEvaluate = varName + ' = varValue'

        except Exception as err:
        if 'bar' in locals():
            # print(locals()['bar']) # (1) OK
            # print(bar)  # (2) ERR
            #print("'bar' OK:", bar)  # (3) ERR
            pass # uncomment any line above


After ``exec()`` is executed, ``bar`` can be seen in ``locals()``, but not accessible by intereter. Also, It can be accessed by directly calling ``print(locals()['bar'](``, but not ``print(bar)``.

This is the problem as long as the code is wrapped in function. If the same code is placed in the module body, works as expected. 

Is there any exaplanation for such behaviour, or is this a bug?
Date User Action Args
2019-03-25 17:31:05schperplatasetrecipients: + schperplata, paul.moore, tim.golden, zach.ware, steve.dower
2019-03-25 17:31:05schperplatasetmessageid: <>
2019-03-25 17:31:05schperplatalinkissue36426 messages
2019-03-25 17:31:05schperplatacreate