<?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: How to keep missing fields from crashing my code? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446001#M34988</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I read the DBF into a fgdb I will have a similar situation as you have?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Aug 2014 15:23:09 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2014-08-21T15:23:09Z</dc:date>
    <item>
      <title>How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445992#M34979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a very helpful code I use to run metrics between land cover and a bunch of assessment boundary feature classes using tabulate area. I put my land cover classes in a list and the field names that are calculated from the classes in another list. Update cursor fills in the rest. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is, if I have an assessment boundary that does not intersect a land cover class, when update cursor goes to calculate the field from the class value, it crashes the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will paste a sample code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;ClassList = ["Forest", "Vegetation"]
FieldList = ["Land_Acres","Forest_Acres", "Forest_Percent", "Veg_Acres", "Veg_Percent"]

m2ac = 0.0002471054

FcList = arcpy.ListFeatureClasses("*", "")&amp;nbsp;&amp;nbsp; 
for fc in FcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; areaTab1 = "Metrics_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in FieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, field, "DOUBLE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; TabulateArea(fc, "GID", LC, "Class", areaTab1 , 1) #"UTC_Metrics_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.JoinField_management(fc, "GID", areaTab1, "GID", ClassList)#"trees11_tab_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[0], (row.Shape_Area * m2ac))#Total Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[1], row.getValue(ClassList[0]) * m2ac) #Forest Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[2], (row.getValue(FieldList[1]) / row.Land_Acres) * 100) #Forest Percent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[3], row.getValue(ClassList[1]) * m2ac) #Veg Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[4], (row.getValue(FieldList[3]) / row.Land_Acres) * 100) #Veg Percent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, this code runs great, unless one of the feature classes does not intersect with one of the land cover classes. Then, when the code calls the ClassList for that value, the code will crash in two spots:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. At the joinfield, where it looking for all classes from the class list to join&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. In the update cursor when it calls the class name to calculate the fields.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there&amp;nbsp; a good way to make the code just skip the value rather than crashing the code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 14:41:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445992#M34979</guid>
      <dc:creator>RichardThurau</dc:creator>
      <dc:date>2012-06-12T14:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445993#M34980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you want your script to process that feature class at all if it doesn't have the required parameters? You could use a try/except block to exit that iteration and go to the next, or you could use a list field check on your feature class to compare against your list of fields that you want to be there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 14:56:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445993#M34980</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-06-12T14:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445994#M34981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mathew Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I absolutely want the code to be able to just: 1. Join all available fields, and 2. Calculate all available fields. Just keep on trucking through the feature class loop even if one feature class does not intersect with a land cover class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought about a try/except for the update cursor, but I think that would still stop the code from calculating remaining fields. For example, if there was no forest, I'd still want it to calculate vegetation. Which a try/except would have to added to each line in the update cursor, correct?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But, I don't see a way to use try/except for the joinfield, where I will get a failure if my tabulate area table does not contain all fields within the ClassList.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 15:14:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445994#M34981</guid>
      <dc:creator>RichardThurau</dc:creator>
      <dc:date>2012-06-12T15:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445995#M34982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Probably not the best solution, but this should keep your loops running even if an individual iteration fails.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in FcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; areaTab1 = "Metrics_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in FieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, field, "DOUBLE")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TabulateArea(fc, "GID", LC, "Class", areaTab1 , 1) #"UTC_Metrics_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.JoinField_management(fc, "GID", areaTab1, "GID", ClassList)#"trees11_tab_" + os.path.basename(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[0], (row.Shape_Area * m2ac))#Total Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[1], row.getValue(ClassList[0]) * m2ac) #Forest Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[2], (row.getValue(FieldList[1]) / row.Land_Acres) * 100) #Forest Percent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[3], row.getValue(ClassList[1]) * m2ac) #Veg Acres
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(FieldList[4], (row.getValue(FieldList[3]) / row.Land_Acres) * 100) #Veg Percent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:56:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445995#M34982</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T19:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445996#M34983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mathew, you are correct. This will keep the code rolling, but doesn't really resolve the issue. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What would be awesome is have a classList based on the land cover. Regardless of what classes intersect, that classList will work. The sample code calculates values for five fields, but the real code has more than 30. The pain is in having to alter the code to match which land cover types intersect (getValue order from the classList).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing that would help, can I build the classList from the tabulate area table? Doing that would allow me to create a list that only contained the intersecting land cover types for each feature class. Then the try/except might work in the update cursor. Depends on where pass sends the code. Currently I think it just passes to the next feature class if any of the updateRow functions do not work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your thoughts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 17:34:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445996#M34983</guid>
      <dc:creator>RichardThurau</dc:creator>
      <dc:date>2012-06-12T17:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445997#M34984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Richard,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did you ever find a way to address this?&amp;nbsp; I'm doing the same thing with a tabulation of land cover types within watershed polygons.&amp;nbsp; Not all of my seven possible land cover types are present in each watershed, so the update cursor has problems with fields that may or may not be present. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 14:04:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445997#M34984</guid>
      <dc:creator>GregBacon</dc:creator>
      <dc:date>2014-08-21T14:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445998#M34985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are ways to avoid your code from crashing and only update those field that exist. I would probably use some dictionaries for this purpose and switch to the da cursors. If you are willing to drop a small part of your data I can have a look what I can do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 14:51:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445998#M34985</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-21T14:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445999#M34986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm posting a simplified table for this example.&amp;nbsp; The table is the result of the Tabulate Area tool and it will be inside a file gdb created by my model.&amp;nbsp; Let's just try to convert the square feet for each cover type to acres.&amp;nbsp; The problem is that you never know which of seven possible cover types you'll have in this table.&amp;nbsp; The path I've started down is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r'G:\users\gis\gbacon\Watershed_Testing\valleyave\WatershedDelineation.gdb'&lt;/P&gt;&lt;P&gt;fldlist = arcpy.ListFields("TabSummary","","Double")&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor("TabSummary",fldlist) as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0:] = row/43560&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The update cursor needs a list of fields, but the fldlist variable can't be used here.&amp;nbsp; The second issue seems to be in my use of row[0:] where I'm trying to say take each value from the first to the last of the possible seven and divide each by 43560.&amp;nbsp; I'm very new to Python and I appreciate your help. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:15:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/445999#M34986</guid>
      <dc:creator>GregBacon</dc:creator>
      <dc:date>2014-08-21T15:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446000#M34987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm afraid you added the XML and not the DBF file itself. Can you add it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:20:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446000#M34987</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-21T15:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446001#M34988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I read the DBF into a fgdb I will have a similar situation as you have?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446001#M34988</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-21T15:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446002#M34989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;some pointers (without having seen the data):&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;are you sure that all double fields need to be updated?&lt;/LI&gt;&lt;LI&gt;the fldlist in your case is a list that contains field objects, but the cursor will need a list or tuple of field names. I changed this on line 4&lt;/LI&gt;&lt;LI&gt;for each row you will need to loop through the fields and calculate the new values (see line 8 - 11)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1408634908214237 jive_text_macro" jivemacro_uid="_1408634908214237" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;arcpy.env.workspace = r'G:\users\gis\gbacon\Watershed_Testing\valleyave\WatershedDelineation.gdb'&lt;/P&gt;
&lt;P&gt;tbl = "TabSummary"&lt;/P&gt;
&lt;P&gt;fldlist = [fld.name for fld in arcpy.ListFields(tbl,"","Double")]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(tbl, fldlist) as cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fld in fldlist:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row&lt;I&gt; = row&lt;I&gt; / 43560&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haven't tested it though. Since you are changing the input data, test it with a copy of the data. Also don't run the code more than once on the same data...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:32:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446002#M34989</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-21T15:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446003#M34990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This worked nicely!  Thank you.  In this case, all “double” fields needed the update.  What would change if I had some “double” fields that needed to be left alone?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just checked the forum and found that my table is in fact in the zip file attachment.  I apologize for not having posted the code correctly. It seems like there’s a better way to do it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:53:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446003#M34990</guid>
      <dc:creator>GregBacon</dc:creator>
      <dc:date>2014-08-21T15:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446004#M34991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only file in the ZIP file is an XML file called "TabSummary.dbf.xml" (or at least this is what passed my firewall).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you know the names of the double fields you want to maintain untouched, you would have to exclude those from the list of fieldnames. This can be done like this (see code below).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the flds_exclude contains a list of fieldnames that should remain untouched&lt;/LI&gt;&lt;LI&gt;flds_touse is a new list where all the items from the exclude list are remove from the list of double fields&lt;/LI&gt;&lt;LI&gt;set() is used to be able to do this type of comparisons with lists, after this the set is converted to a list again&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14086374249944000" jivemacro_uid="_14086374249944000"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;arcpy.env.workspace = r'G:\users\gis\gbacon\Watershed_Testing\valleyave\WatershedDelineation.gdb'&lt;/P&gt;
&lt;P&gt;tbl = "TabSummary"&lt;/P&gt;
&lt;P&gt;fldlist = [fld.name for fld in arcpy.ListFields(tbl,"","Double")]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;flds_exclude = ["myFieldname1", "myFieldname2", "myFieldname3"]&lt;/P&gt;
&lt;P&gt;flds_touse = list(set(fldlist) - set(flds_exclude))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(tbl, flds_touse) as cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fld in flds_touse:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row&lt;I&gt; = row&lt;I&gt; / 43560&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 16:12:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446004#M34991</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-21T16:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep missing fields from crashing my code?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446005#M34992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again.  Set() could be very useful to me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Aug 2014 17:18:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-missing-fields-from-crashing-my-code/m-p/446005#M34992</guid>
      <dc:creator>GregBacon</dc:creator>
      <dc:date>2014-08-21T17:18:36Z</dc:date>
    </item>
  </channel>
</rss>

