<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update Cursor string error and attribute error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329773#M68672</link>
    <description>&lt;P&gt;Try changing your table variable from&amp;nbsp;parameters[0].valueAsText to&amp;nbsp;parameters[0].value?&lt;/P&gt;&lt;P&gt;You're already asking for a table in the parameter, but you're feeding the cursor a string. Might be something else, but I'd at least give it a shot.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Sep 2023 18:54:26 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2023-09-18T18:54:26Z</dc:date>
    <item>
      <title>Update Cursor string error and attribute error</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329771#M68670</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;File "&amp;lt;string&amp;gt;", line 69, in execute
AttributeError: __enter__&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 18:48:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329771#M68670</guid>
      <dc:creator>RyShissler_Welland</dc:creator>
      <dc:date>2023-09-18T18:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor string error and attribute error</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329773#M68672</link>
      <description>&lt;P&gt;Try changing your table variable from&amp;nbsp;parameters[0].valueAsText to&amp;nbsp;parameters[0].value?&lt;/P&gt;&lt;P&gt;You're already asking for a table in the parameter, but you're feeding the cursor a string. Might be something else, but I'd at least give it a shot.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 18:54:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329773#M68672</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-09-18T18:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor string error and attribute error</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329780#M68673</link>
      <description>&lt;P&gt;Hmmm I got the same error with .value unfortunately.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 19:05:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329780#M68673</guid>
      <dc:creator>RyShissler_Welland</dc:creator>
      <dc:date>2023-09-18T19:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor string error and attribute error</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329797#M68674</link>
      <description>&lt;P&gt;Okay, so I'd still not use valueAsText here.&lt;/P&gt;&lt;P&gt;But.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try using arcpy.da.UpdateCursor instead; it didn't throw any errors for me.&lt;/P&gt;&lt;P&gt;Oh wait that's probably the issue; arcpy.UpdateCursor and arcpy.da.UpdateCursor have different parameters.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 19:40:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329797#M68674</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-09-18T19:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor string error and attribute error</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329821#M68675</link>
      <description>OMG yes, that worked! Thank you!&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Sep 2023 20:01:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-string-error-and-attribute-error/m-p/1329821#M68675</guid>
      <dc:creator>RyShissler_Welland</dc:creator>
      <dc:date>2023-09-18T20:01:21Z</dc:date>
    </item>
  </channel>
</rss>

