Let's that I have the following Python script script.py:
a = 1
b = 10
for i in range(b):
a += 1
print(a)
I know that I can use globals() inside this script.py in order to show the namespace:
{'__file__': 'counter.py', '__doc__': None, 'i': 9, '__spec__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000027C8D9402E8>, '__name__': '__main__', '__cached__': None, 'b': 10, 'a': 11, '__package__': None, '__builtins__': <module 'builtins' (built-in)>}
I wonder whether you can somehow emulate globals() from outside the script.py? In other words, I want to run other_script.py and see the script.py's globals() output. Is import counter somehow useful?
EDIT: if possible, can script.py's globals output be updated with each increment of i in the for loop?
script.pyandother_script.pystarted separately (ie as completely separate processes) or do you intend for one to start the other? As completely sperrate processes I don't believe you should be able to do much but you may have some options if one is the subprocess of the other using pythons multiprocessing module.script.pyandother_script.pyare completely separate processes.