Recompute restarted Python's global symbol table

The code below does not work in the script component as expected. @eirannejad

if 'i' not in globals() or reset:
    i = 0
i += 1
a = i


globals.gh (10.5 KB)

I know in this example it is possible to achieve the same goal with sticky variables, however globals() would be necessary in other scenarios.

import scriptcontext as sc
if 'i' not in sc.sticky.keys() or reset:
    sc.sticky['i'] = 0
sc.sticky['i'] += 1
a = sc.sticky['i']
1 Like

GhPython script and new script components do not share sticky variables. It would be handy if we could share variables between these two.
Sticky.gh (10.6 KB)

This old conversation might useful for full context here. It would indeed be good for the new editor to behave as much as GHPython as possible when it comes to such features.

1 Like

Working on a fix right now: RH-74305 CPython should keep using the same scope for a script instance like legacy Python

2 Likes