How to design configurable scripts for non-programmers
I have a python script that allows users to parse addresses when batch-editing a table.
The script allows the user to choose whether to return the house number or the street name to the field (by commenting-out the non-applicable ReturnType
line).
Unfortunately, traditional user interfaces are not possible in the Field Calculator tool that we use. The only way I know of that the user can configure a script is to manually adjust the code.
def addressParser(inString):
###Note to users:
###Comment-out the ReturnType option that does not apply.
returnType = "House Number"
#returnType = "Street Name"
splitString = inString.split(' ',1)
houseNumber = splitString[0]
streetName = splitString[1]
if returnType == "House Number":
if houseNumber.isdigit():
return houseNumber
else:
return
if returnType == "Street Name":
return streetName
else:
return
__esri_field_calculator_splitter__
addressParser(!ADDRESS!)
The script seems simple enough to me, as a novice programmer.
However, when I write up the release notes for the script, it starts sounding awfully complicated for something that is really quite simple.
Step #3 is the one that I'm most concerned about.
Release Notes:
I’ve made a field calculator tool (python) that can be used to parse address fields. The tool works similarly to how we use the Text to Columns tool in Excel to parse addresses.
For example, 123 Main St E can get parsed to return either the house number or the street name:
- 123
- Main St E
The tool works by splitting the text at the first instance of a space (‘ ‘).
Steps:
- Load the tool into the Field Calculator by clicking the Load button.
- Switch the Field Calculator mode from VB Script to Python.
Specify which part of the address (house number or street name) that the tool will return to your field by removing or adding the number sign (#) in front of the appropriate line.
- Hint: the number sign (#) is the ‘comment out/cancel out’ symbol in python.
Example: To return the house number, you would leave the code as-is:
returnType = "House Number" #returnType = "Street Name"
Or, to return the street name, you would switch the number sign (#) from the street name line to the house number line:
#returnType = "House Number" returnType = "Street Name"
Specify the field that the un-parsed address is coming from:
- Example: Change
addressParser( !YourUnparsedAddressFieldHere!)
- To
addressParser( !ADDRESS!)
- Click OK to run the tool.
How can I make this configurable script be more user-friendly for non-programmers?
- Modify the script so that the configuration is easier?
- Modify the instructions?