I'm new to scripting and I'm trying to create a tool that takes street address from one field, makes it into a internal link, and then adds it to another field. I keep running into an error on line 69. I can't seem to find a solution.
File "<string>", line 69, in execute
AttributeError: __enter__
def addressParser(address):
try:
splitAddress = address.split(' ' , 1)
firstLetter = splitAddress[1][0]
streetName = splitAddress[1]
except:
arcpy.AddMessage('An error occurred while updating ' + address + '.')
return firstLetter , streetName
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = "toolbox"
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Water Service Linker"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
param0 = arcpy.Parameter( # Allows user to select the table on which they'd like the action performed
displayName = 'Table',
name = 'param0',
datatype = 'GPTableView',
parameterType = 'Required',
direction = 'Input')
params = [param0]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""This tool will add folder link data to the WtrSrvcInstall Field"""
table = parameters[0].valueAsText # converts the parameter to a useable string
arcpy.AddMessage(table)
fields = ['Civic_Name_Label' , 'WtrSrvcInstall'] #Defines the fields we'll be working in
addressField = 'Civic_Name_Label' # The field title that contains the address info
#linkField = 'WtrSrvcInstall' # The field title that will be the destination for the links
folderBase = '\\\\polaris\\Infrastructure_ScanFiles\\WaterServiceSheets' # Sets the base link under which all other links exist
arcpy.AddMessage(folderBase)
#try:
with arcpy.UpdateCursor(table , fields) as cursor: # sets the cursor in the correct table and fields
for row in cursor: # iterates through each row
first , street = addressParser(row[0])
folderFull = folderBase + '\\' + first + '\\' + street
arcpy.AddMessage(folderFull)
row[1] = folderFull
#except:
#arcpy.AddMessage('An error occurred')
return
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return