<?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 delete multiple field using python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484280#M37797</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;System Windows Vista / ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have ten shape files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Each of them has the fields starting with D in the attribute table. (D8739, D1983)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Some have 10 D fields, and other have about 20.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I want to delete the D fields using python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, no D field was deleted after running the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly help to modify it and thank you in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Script Name: calculate sum ##Description: calculate sum of merged range sizes of a taxonomy of migratory birds&amp;nbsp; ##Created By: Elaine Kuo ##Date: 26/05/2012&amp;nbsp;&amp;nbsp;&amp;nbsp; #Import standard library modules import arcgisscripting import os&amp;nbsp; #Create the Geoprocessor object gp = arcgisscripting.create(9.3)&amp;nbsp; #Set the workspace. gp.Workspace= "H:/temp_D/test_1" #gp.Workspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O/P_Turdidae_22"&amp;nbsp; #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D" #outWorkspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O"&amp;nbsp; #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated for fc in fcs:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object. &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer(fc,"lyr") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.ListFields("lyr") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name[1:4] == "D": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.deletefield ("lyr", field.name)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace. &amp;nbsp;&amp;nbsp;&amp;nbsp; #OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # copy feature &amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.CopyFeatures("lyr", OutFeatureClass)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # clear memory of layers &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete("lyr")&amp;nbsp; gp.AddMessage(gp.GetMessages()) print gp.GetMessages()&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 28 Jul 2013 05:41:32 GMT</pubDate>
    <dc:creator>ElaineKuo</dc:creator>
    <dc:date>2013-07-28T05:41:32Z</dc:date>
    <item>
      <title>delete multiple field using python</title>
      <link>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484280#M37797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;System Windows Vista / ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have ten shape files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Each of them has the fields starting with D in the attribute table. (D8739, D1983)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Some have 10 D fields, and other have about 20.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I want to delete the D fields using python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, no D field was deleted after running the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly help to modify it and thank you in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Script Name: calculate sum ##Description: calculate sum of merged range sizes of a taxonomy of migratory birds&amp;nbsp; ##Created By: Elaine Kuo ##Date: 26/05/2012&amp;nbsp;&amp;nbsp;&amp;nbsp; #Import standard library modules import arcgisscripting import os&amp;nbsp; #Create the Geoprocessor object gp = arcgisscripting.create(9.3)&amp;nbsp; #Set the workspace. gp.Workspace= "H:/temp_D/test_1" #gp.Workspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O/P_Turdidae_22"&amp;nbsp; #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D" #outWorkspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O"&amp;nbsp; #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated for fc in fcs:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object. &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer(fc,"lyr") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.ListFields("lyr") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name[1:4] == "D": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.deletefield ("lyr", field.name)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace. &amp;nbsp;&amp;nbsp;&amp;nbsp; #OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # copy feature &amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.CopyFeatures("lyr", OutFeatureClass)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # clear memory of layers &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete("lyr")&amp;nbsp; gp.AddMessage(gp.GetMessages()) print gp.GetMessages()&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 05:41:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484280#M37797</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2013-07-28T05:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: delete multiple field using python</title>
      <link>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484281#M37798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For your example field names D8739, D1983 field.name[1:4] is&amp;nbsp; 873 and 198. You need to test field.name[0] == 'D'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name[0] == "D": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.deletefield ("lyr", field.name)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 07:01:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484281#M37798</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2013-07-28T07:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: delete multiple field using python</title>
      <link>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484282#M37799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks. It works well!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 11:18:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-multiple-field-using-python/m-p/484282#M37799</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2013-07-28T11:18:26Z</dc:date>
    </item>
  </channel>
</rss>

