Revision 0de969c2-2cf3-491a-8874-3c478736c41c - Stack Overflow

As I understood:
- something is needed to be loaded
- it is needed to be loaded often, because file with code which uses this something is edited often
- you don't want to wait until it will be loaded every time

Maybe such solution will be okay for you.

You can write script loader file in such way:
```Python
import importlib.util, traceback, sys

# Example data
something = [123]

modules_before = list(sys.modules.keys())
while True:
 # Change according the file name
 spec = importlib.util.spec_from_file_location('some_file', 'some_file.py')
 mod = importlib.util.module_from_spec(spec)
 # Change to needed global name in the target module
 mod.something = something
 try:
 spec.loader.exec_module(mod)
 except KeyboardInterrupt:
 raise
 except:
 traceback.print_exc()
 del mod, spec
 modules_after = list(sys.modules.keys())
 for k in modules_after:
 if k not in modules_before:
 del sys.modules[k]
 # Press enter to restart
 input()
```

Example of module:
```Python
# Change 1 to some different number when first script is running and press enter
something[0] += 1 
print(something)
```


AltStyle によって変換されたページ (->オリジナル) /