<?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: adding and updating field using class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160657#M64266</link>
    <description>&lt;P&gt;You should only pass 2 parameters to the init function - 'self'&amp;nbsp; is sort of implied, which I find confusing coming from a C++ background. Anyway - here is how I would do it which I think is a bit clearer. It didn't look like you were using the FID field so I got rid of it - and I now see how you calculate the assessment.&amp;nbsp; Using a class to calculate the assessment seems like overkill, but you must have a reason to use it .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cursor = arcpy.da.UpdateCursor(fc, ["Landuse","Value", "Tax"])
for land_use, value, tax in cursor:
    myparcel = parcelclass.parcel(land_use, value)  
    mytax = myparcel.assessment()   
    cursor.updateRow([land_use, value, mytax])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 04:53:16 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2022-04-04T04:53:16Z</dc:date>
    <item>
      <title>adding and updating field using class</title>
      <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160627#M64263</link>
      <description>&lt;P&gt;So, i am tryinrg to solve this problem!&lt;/P&gt;&lt;P&gt;"You are given a feature class called parcels.shp that contains the following fields: FID, Shape, Landuse, and&lt;BR /&gt;Value. You need to write a script that determines the property tax and writes these values to the same feature&lt;BR /&gt;class in a new field called Tax."&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am stuck when it comes to adding and updating the Tax field. this is what i have so far. any hint would be very helpful. thanks&lt;/P&gt;&lt;P&gt;class parcel(object):&lt;/P&gt;&lt;P&gt;def __init__(self,landuse,value):&lt;BR /&gt;self.landuse = landuse&lt;BR /&gt;self.value = value&lt;/P&gt;&lt;P&gt;def assessment(self):&lt;BR /&gt;if self.landuse == "SFR":&lt;BR /&gt;rate = 0.05&lt;BR /&gt;elif self.landuse == "MFR":&lt;BR /&gt;rate = 0.04&lt;BR /&gt;else:&lt;BR /&gt;rate = 0.02&lt;/P&gt;&lt;P&gt;assessment = self.value*rate&lt;BR /&gt;return assessment&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import parcelclass&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:/Lab8"&lt;/P&gt;&lt;P&gt;fc = "parcels.shp"&lt;/P&gt;&lt;P&gt;arcpy.AddField_management(fc, "Tax", "LONG", "", "", 10)&lt;/P&gt;&lt;P&gt;cursor = arcpy.da.UpdateCursor(fc, ["FID","Landuse","Value"])&lt;/P&gt;&lt;P&gt;for row in cursor:&lt;/P&gt;&lt;P&gt;myparcel = parcelclass.parcel(row[1],row[2],row[3])&lt;/P&gt;&lt;P&gt;mytax = myparcel.assessment()&lt;/P&gt;&lt;P&gt;cursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 00:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160627#M64263</guid>
      <dc:creator>KristenTowsend</dc:creator>
      <dc:date>2022-04-04T00:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: adding and updating field using class</title>
      <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160628#M64264</link>
      <description>&lt;P&gt;It would be best if you format your code so we can see the indentation and explain what you mean by being "stuck".&amp;nbsp; Without putting a lot of thought into it (since it seems the objective is for you to figure it out) I would try something along these lines, in terms of writing out the calculated tax value :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;cursor = arcpy.da.UpdateCursor(fc, ["FID","Landuse","Value", "Tax"])
for row in cursor:
    myparcel = parcelclass.parcel(row[1],row[2],row[3])  # This doesn't look right
    mytax = myparcel.assessment()   # This call appears to only return the rate, not the assessment
    cursor.updateRow(row[1],row[2],row[3], mytax)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 00:51:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160628#M64264</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-04-04T00:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: adding and updating field using class</title>
      <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160631#M64265</link>
      <description>&lt;P&gt;Hi , so below is the formatted code pic&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KristenTowsend_0-1649034073468.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38059i949941E1CF5BF4DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KristenTowsend_0-1649034073468.png" alt="KristenTowsend_0-1649034073468.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;when i run the code i get the following error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;myparcel = parcelclass.Parcel(row[1],row[2],row[3])&lt;BR /&gt;TypeError: __init__() takes 3 positional arguments but 4 were given&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 01:02:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160631#M64265</guid>
      <dc:creator>KristenTowsend</dc:creator>
      <dc:date>2022-04-04T01:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: adding and updating field using class</title>
      <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160657#M64266</link>
      <description>&lt;P&gt;You should only pass 2 parameters to the init function - 'self'&amp;nbsp; is sort of implied, which I find confusing coming from a C++ background. Anyway - here is how I would do it which I think is a bit clearer. It didn't look like you were using the FID field so I got rid of it - and I now see how you calculate the assessment.&amp;nbsp; Using a class to calculate the assessment seems like overkill, but you must have a reason to use it .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cursor = arcpy.da.UpdateCursor(fc, ["Landuse","Value", "Tax"])
for land_use, value, tax in cursor:
    myparcel = parcelclass.parcel(land_use, value)  
    mytax = myparcel.assessment()   
    cursor.updateRow([land_use, value, mytax])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 04:53:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160657#M64266</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-04-04T04:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: adding and updating field using class</title>
      <link>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160862#M64274</link>
      <description>&lt;P&gt;thank you! but for some reason, I think the code isn;t working for line 3.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 17:38:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-and-updating-field-using-class/m-p/1160862#M64274</guid>
      <dc:creator>KristenTowsend</dc:creator>
      <dc:date>2022-04-04T17:38:29Z</dc:date>
    </item>
  </channel>
</rss>

