when using imported modules and one of the modules changes, ArcGIS PRO does not reflect that change, but runs the old version. it seems to cache it somehow.
the only way to get the changes to run is to restart PRO.
py script 1 that is actually run via toolbox:
py script 2 that is imported:
Is there a way around this?
Any input welcome!
You had better check out some of my blog posts dealing with python... especially the transition from 2.7 to 3.4/3.5
>>> import importlib >>> dir(importlib) ['_RELOADING', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__import__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_bootstrap', '_bootstrap_external', '_imp', '_r_long', '_w_long', 'abc', 'find_loader', 'import_module', 'invalidate_caches', 'machinery', 'reload', 'sys', 'types', 'util', 'warnings'] >>> help(importlib.reload) Help on function reload in module importlib: reload(module) Reload the module and return it. The module must have been successfully imported before.
I am glad you got it working. I highly recommend you read the documentation on importlib.reload() . As powerful and handy as reload() is, there is some fine print with its use. Without understanding the nuances and caveats of using it, you could get yourself wrapped around an axle at some point.
As Joshua point out, do read the fine print.
I generally do the reload from the command line should I need to edit a script that has been imported.
Should you feel the need to include it in a script, you must remember to comment the reload line(s) before your final commit.
It is also a simpler idea to simply delete references to the imported module(script) and its imports while you are editing..
In fact, get used to using your builtins... in this example I cleaned out the 'fluff', found what is currently been loaded, imported a module (aka script), deleted it then examined if it was still around
>>> locals().keys() dict_keys(['__builtins__']) >>> import find >>> locals().keys() dict_keys(['find', '__builtins__']) >>> dir(find) ['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__private__', '__spec__', '_demo', '_func', '_large', 'dedent', 'find', 'ft', 'np', 'script', 'sys'] >>> >>> del find >>> locals().keys() dict_keys(['__builtins__']) >>>
So, you really don't need any form of reloading, if you understand the command line.