Python Gurus,
I have downloaded the Spatial Analyst Supplemental Tools which is a Python Toolbox and there appears to be a bug in the Peak tool. I know a little bit of Python and thought I would have a crack at debugging it, primarily to teach myself how to use a Python toolbox. I am use to creating python script tools but not a Python toolbox.
Anyway every time I tweak the code in the Peak tool and try to run it, it's as if the tool has been cached and none of my tweaks run. I looked at help and found this page and in the tip section it talks about imported modules needing reloading. I think this is my problem none of my changes are being refreshed. But the import statement is "from peaktool import Peak". If I type reload(peaktool) it says "name 'peaktool' is not defined". So the help page gives advice but does not explicity show you how to do it!
So my question is how do you reload a module when the importing of it is in the format of "from peaktool import Peak" and where would one put the reload statement in the code? Below is the Python toolbox code.
import sys import os import arcpy myScripts = os.path.join(os.path.dirname(__file__), "Scripts") sys.path.append(myScripts) from dendrogrampdf import CreateDendrogram from viewshedalongpath import ViewshedAlongPath from maxelevation import MaximumUpstreamElevation from drawsig import DrawSignatures from filledcontours import FilledContours from peaktool import Peak from eraserastervalues import EraseRasterValues from zonalstatisticsastable02 import ZonalStatisticsAsTable02 from tabulatearea02 import TabulateArea02 class Toolbox(object): def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Spatial Analyst Supplemental Tools" self.alias = "sas" # List of tool classes associated with this toolbox self.tools = [CreateDendrogram, DrawSignatures, ViewshedAlongPath,MaximumUpstreamElevation, FilledContours, Peak, EraseRasterValues,ZonalStatisticsAsTable02,TabulateArea02]
Peak is a Class in the peaktools module.
Solved! Go to Solution.
import peaktool print peaktool.__file__
import peaktool reload(peaktool) # *should* recompile pyc file from peaktool import Peak #should now be updated
import peaktool print peaktool.__file__
import peaktool reload(peaktool) # *should* recompile pyc file from peaktool import Peak #should now be updated
import SomeStuffIWrote
import peaktool reload(peaktool) from peaktool import Peak
Hi Duncan
I still find this to be a pain... But what I really want to add is: If you have your .pyt import a .py and you are then editing the .py then you need to reload recursively. How to do that is described here: Is there a way to refresh imported modules in a ArcGIS Python Toolbox? - Geographic Information Syst...
Best regards
Martin