Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geography 465 Managing Custom Python Script Tools

Similar presentations


Presentation on theme: "Geography 465 Managing Custom Python Script Tools"— Presentation transcript:

1 Geography 465 Managing Custom Python Script Tools

2 Considerations for Creating Script Tools
End User Purpose of the script tools Toolbox organization Documentation Code structure Reusable components, error handling, more How to implement Where to store, how to distribute, future tools, etc. Mainteance issues

3 Organizing your script tools
Create the script tools (associate each with a .py script) Group common tools into toolsets Group toolsets into toolbox

4 Understanding program flow
Top-level file (.py file) Module that you can run Controls the flow Can import other modules (.py files) Module_1 Module_A Module_B Module_C Module_D Top-level file Imported modules

5 Example: Spatial Statistics Toolbox
DirectionalDistribution.py Top-level file CentralFeature.py sys os locale HelperFunctions sys os locale HelperFunctions sys os locale math random Other spatial statistics tools import HelperFunctions HelperFunctions.py import sys, math, os, locale, random, tempfile, arcgisscripting

6 Ways of importing More than one way to import
import; entire module; requires module prefix import math math.sin (x) from…import; specific names from module from math import sin, cos, sin(x) from…import * from math import * tan (x) Affects: readability, name collision, ability to reload

7 Code order Writing custom functions Functions: Put functions at top
Put top-level code at bottom so functions are recognized Functions: def… top-level code…

8 Controlling access to functions and variables
Each module has a built in _ _name_ _atttribute Module can test its own _ _name_ _ Top-level file module: _ _name_ _ is equal to _ _main_ _ Imported module: _ _name_ _ is equal to <modulename> _ _main_ _ prevents access when module is imported for def statements Variables

9 Code example: Control access
MyTool.py import Example fmc = Example.find_most_central() ac = Example.areaCalc() Example.py import arcgisscripting gp = arcgisscripting.create() def get_imputs (arguments): # access unrestricted df find_most_central(): # in calling module if _ _name_ _ = “_ _main_ _”: # access restricted def areaCalc(…) # in calling module


Download ppt "Geography 465 Managing Custom Python Script Tools"

Similar presentations


Ads by Google