Shotgun Python Console annoying scoping

The python console is unable to use global variables inside of functions and some other scopes.

This makes it really annoying when trying to test out engine or app code interactively.

x = 5

def test():
    print x
test()

For example this code gives me NameError: global name 'x' is not defined

Hi Joe

Unfortunately this a known issue, which we have ticketed up.
I’m not sure when this will get addressed, at the moment.

Apologies
Phil

doing this in the exec block of input_widget.py seems to work, at least for my example above

I’m not sure if I should update the eval block as well.
I can probably clean this up and submit a pull request.

d = dict(globals(), **self._locals)
exec(python_code, d, d)

d2 = dict(globals(), **self._locals)
for k in d:
    if (k in d2 and d2[k] != d[k]) or k not in d2:
        self._locals[k] = d[k]

submitted fix

That’s really awesome, thanks a lot Joe!
I’ve updated our internal ticket with your Pull request link.

Just to let you know, we’ve released a new version of tk-multi-pythonconsole which contains your fix. The new version is v1.2.1.

Thanks again @jhultgre!