<?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: If feature class has the same name as feature class in another database in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439067#M34465</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the response, that works.&amp;nbsp; Well it did until our IT group decided to change somethings.&amp;nbsp; Now the feature classes in the staging database are all prefixed.&amp;nbsp; So an example is in staging MGISSP.GISONEAST.PERM_ABA_Roads and the same feature class in Prod is MGISP.GISONEAST.PERM_ABA_Roads.&amp;nbsp; Notice the difference at the beginning, staging is MGISSP and prod is MGISP.&amp;nbsp; As a result your solution doesnt work any longer.&amp;nbsp; Any other ideas?&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Again thanks for the help!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The solution for such an issue is very simple using python and string replacement. If you are going to be using python scripts and tools in a production setting I'd recommend you learn the basics of python so you understand what your tools are doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a good place to start.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/release/2.6.5/library/stdtypes.html?highlight=.replace#str.replace"&gt;http://docs.python.org/release/2.6.5/library/stdtypes.html?highlight=.replace#str.replace&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Dec 2012 12:16:18 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2012-12-20T12:16:18Z</dc:date>
    <item>
      <title>If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439061#M34459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have two databases (Staging and Prod) each containing the same feature classes.&amp;nbsp; I want to append the data from each individual feature class in the staging.gdb to its matching feature class in the Prod.gdb.&amp;nbsp; What is the most efficient way of writing this in python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently i am using the append tool for each individual feature class. this is making the script kind of long and a lot to maintain if something changes as I have 20 appends to account for the 20 different feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Staging.gdb&amp;nbsp; ...........&amp;nbsp;&amp;nbsp; Prod.gdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wetlands&amp;nbsp; --append--&amp;gt; Wetlands&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Streams&amp;nbsp;&amp;nbsp; --append--&amp;gt;&amp;nbsp; Streams&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 13:24:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439061#M34459</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-12-06T13:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439062#M34460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There are many ways to do this, but have you just tried deleting the old feature class and copying the new one in?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also use insert cursors to insert new rows from your source db to your destination db.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 13:53:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439062#M34460</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2012-12-06T13:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439063#M34461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;See the attachment.&amp;nbsp; This is how I am currently doing it.&amp;nbsp; It works fine, I just see it as inefficient.&amp;nbsp; Shouldn't there be a way to say something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If feature class name from database "A" matches feature class name from database "B" then append those features from "A" to "B".&amp;nbsp; This way each append function doesn't have to be written out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Keep in mind I'm still learning python, I've only been involved with it for about a month now.&amp;nbsp; Thanks, I appreciate the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 10:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439063#M34461</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-12-07T10:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439064#M34462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So no responses on this?&amp;nbsp; I'll assume i'm doing it correctly then?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Dec 2012 18:44:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439064#M34462</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-12-11T18:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439065#M34463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;So no responses on this?&amp;nbsp; I'll assume i'm doing it correctly then?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would probably do something like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import sys
import traceback
import arcpy

sde_prod = r"Database Connections\GENERAL_DATA-PROD.sde"
sde_stage = r"Database Connections\STAGING-PROD.sde"

# I find this useful to add
if not arcpy.Exists(sde_prod) or not arcpy.Exists(sde_stage):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add contingency sde connection file on network
&amp;nbsp;&amp;nbsp;&amp;nbsp; sde_prod = "somwhere1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; sde_stage = "somewhere2"

arcpy.env.workspace = sde_prod

fcList = arcpy.ListFeatureClasses("*PERM_ABA*")
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.DeleteFeatures_management(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Delete {0}".format(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Append_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.path.join(sde_stage, fc), os.path.join(sde_prod, fc), "TEST")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Append {0}".format(fc)

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the tool error messages
&amp;nbsp;&amp;nbsp;&amp;nbsp; msgs = arcpy.GetMessages(2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Return tool error messages for use with a script tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(msgs)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print tool error messages for use in Python/PythonWin
&amp;nbsp;&amp;nbsp;&amp;nbsp; print msgs
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the traceback object
&amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; tbinfo = traceback.format_tb(tb)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Concatenate information together concerning the error into a message
&amp;nbsp;&amp;nbsp;&amp;nbsp; pymsg = "PYTHON ERRORS:\nTraceback info:\n{0}\nError Info:\n{1}".format(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tbinfo, sys.exc_info()[1])

&amp;nbsp;&amp;nbsp;&amp;nbsp; msgs = "ArcPy ERRORS:\n{0}\n".format(arcpy.GetMessages(2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Return python error messages for use in script tool or Python Window
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(pymsg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(msgs)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print Python error messages for use in Python / Python Window
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "{0}\n".format(pymsg)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print msgs
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:38:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439065#M34463</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T19:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439066#M34464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response, that works.&amp;nbsp; Well it did until our IT group decided to change somethings.&amp;nbsp; Now the feature classes in the staging database are all prefixed.&amp;nbsp; So an example is in staging MGISSP.GISONEAST.PERM_ABA_Roads and the same feature class in Prod is MGISP.GISONEAST.PERM_ABA_Roads.&amp;nbsp; Notice the difference at the beginning, staging is MGISSP and prod is MGISP.&amp;nbsp; As a result your solution doesnt work any longer.&amp;nbsp; Any other ideas?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 11:24:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439066#M34464</guid>
      <dc:creator>LouisEarly</dc:creator>
      <dc:date>2012-12-20T11:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: If feature class has the same name as feature class in another database</title>
      <link>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439067#M34465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the response, that works.&amp;nbsp; Well it did until our IT group decided to change somethings.&amp;nbsp; Now the feature classes in the staging database are all prefixed.&amp;nbsp; So an example is in staging MGISSP.GISONEAST.PERM_ABA_Roads and the same feature class in Prod is MGISP.GISONEAST.PERM_ABA_Roads.&amp;nbsp; Notice the difference at the beginning, staging is MGISSP and prod is MGISP.&amp;nbsp; As a result your solution doesnt work any longer.&amp;nbsp; Any other ideas?&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Again thanks for the help!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The solution for such an issue is very simple using python and string replacement. If you are going to be using python scripts and tools in a production setting I'd recommend you learn the basics of python so you understand what your tools are doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a good place to start.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/release/2.6.5/library/stdtypes.html?highlight=.replace#str.replace"&gt;http://docs.python.org/release/2.6.5/library/stdtypes.html?highlight=.replace#str.replace&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 12:16:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-feature-class-has-the-same-name-as-feature/m-p/439067#M34465</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-12-20T12:16:18Z</dc:date>
    </item>
  </channel>
</rss>

