<?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: Overwrite of output not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26078#M1951</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't know if it's a python issue or an ESRI/arcpy issue and I don't know why, but this last tidbit of info (try:except) solved a problem I've been having off and on for months.&amp;nbsp; Halle-freaking-lujah ! Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Oct 2012 14:03:30 GMT</pubDate>
    <dc:creator>LaurelKish</dc:creator>
    <dc:date>2012-10-24T14:03:30Z</dc:date>
    <item>
      <title>Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26072#M1945</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 script that writes .dbf files to a folder. The first time the script runs it does what it is supposed to. The second time I run it however, it says the first .dbf to be created already exists and stops. It's not overwriting the files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have arcpy.env.overwriteOutput = True and had it successfully working to overwrite at one point in the development of the script. I'm not sure what made it stop working. I'm pretty sure I added the field mapping and the listing of the files in the log file after it was running smoothly but, have commented them out and it still gives me the error message. Any suggestions would be appreciated....I have no idea what is causing the problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, sys, traceback, time, datetime, os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set overwrite option&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# INPUT NEEDED: Set Read me file workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CURDATE = datetime.date.today()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;logpath = "X:\\Script\Out\ReadMe"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;logfile1 = logpath + str (" ") + str(CURDATE) + ".txt"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if arcpy.Exists(logfile1):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(logfile1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;log1 = open(logfile1, "a")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Generate Readme file " + str(CURDATE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print &amp;gt;&amp;gt; log1, time.strftime("%c")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print &amp;gt;&amp;gt; log1, "End Processing "&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set the current workspace for input file geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "X:\\Script\Input.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set Local variables specifyting the output table folder:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outTable = "X:\\Script\Out"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Start Processing"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set a Search Cursor on the Polygons&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;srow = srows.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Get Polygon"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mapFields = ["ID", "STUDY", "NAME"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldMappings = arcpy.FieldMappings()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for mapField in mapFields:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap = arcpy.FieldMap()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap.addInputField("Points", mapField)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings.addFieldMap(fieldMap)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;while srow:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pid = srow.ObjectID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_lyr = arcpy.MakeFeatureLayer_management("Polygons",'pgon_select',""" "ObjectID" = """+ str(pid))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Watershed is " + str(srow.WATERSHED)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("Points", "Points_lyr", "", "",&amp;nbsp; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Make point feature layer"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Points_lyr", "INTERSECT", "pgon_select", "", "NEW_SELECTION")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Select points by " + str(srow.WATERSHED) + " watershed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToTable_conversion("Points_lyr", outTable , str(srow.WATERSHED)+ ".dbf","")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Make table " + str(srow.WATERSHED)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; srow = srows.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Next Polygon"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Write .dbf tables to log file"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print &amp;gt;&amp;gt; log1, "Files generated = "&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file_list = os.listdir(outTable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for file in file_list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if file.endswith (".dbf"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log1.write(file + "\n")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "End Processing"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;log1.close()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 21:55:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26072#M1945</guid>
      <dc:creator>JennyAxelrod</dc:creator>
      <dc:date>2012-09-10T21:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26073#M1946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Honor the Zen of Python&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second line of the Zen of Python doxology is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Explicit is better than implicit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is better to test for and remove files you want to replace (Explicit )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;than to rely on an Arc environment setting (implicit).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Although python can import arcpy, python is not itself arcpy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It does not necessarily honor an Arc environment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can get the Zen of Python by typing &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import this&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;on the Python command line.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2012 10:53:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26073#M1946</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2012-09-11T10:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26074#M1947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;I have a script that writes .dbf files to a folder. The first time the script runs it does what it is supposed to. The second time I run it however, it says the first .dbf to be created already exists and stops. It's not overwriting the files.&lt;BR /&gt;I have arcpy.env.overwriteOutput = True and had it successfully working to overwrite at one point in the development of the script. I'm not sure what made it stop working. I'm pretty sure I added the field mapping and the listing of the files in the log file after it was running smoothly but, have commented them out and it still gives me the error message. Any suggestions would be appreciated....I have no idea what is causing the problem.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import arcpy module import arcpy, sys, traceback, time, datetime, os&amp;nbsp; # Set overwrite option arcpy.env.overwriteOutput = True&amp;nbsp; # INPUT NEEDED: Set Read me file workspace CURDATE = datetime.date.today() logpath = "X:\\Script\Out\ReadMe" logfile1 = logpath + str (" ") + str(CURDATE) + ".txt"&amp;nbsp;&amp;nbsp; if arcpy.Exists(logfile1): &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(logfile1)&amp;nbsp; log1 = open(logfile1, "a")&amp;nbsp; print "Generate Readme file " + str(CURDATE) print &amp;gt;&amp;gt; log1, time.strftime("%c") print &amp;gt;&amp;gt; log1, "End Processing "&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set the current workspace for input file geodatabase arcpy.env.workspace = "X:\\Script\Input.gdb"&amp;nbsp; #Set Local variables specifyting the output table folder: outTable = "X:\\Script\Out"&amp;nbsp; print "Start Processing"&amp;nbsp; #Set a Search Cursor on the Polygons srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" ) srow = srows.next()&amp;nbsp; print "Get Polygon"&amp;nbsp; mapFields = ["ID", "STUDY", "NAME"] fieldMappings = arcpy.FieldMappings() for mapField in mapFields: &amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap = arcpy.FieldMap() &amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMap.addInputField("Points", mapField) &amp;nbsp;&amp;nbsp;&amp;nbsp; fieldMappings.addFieldMap(fieldMap)&amp;nbsp;&amp;nbsp; while srow:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pid = srow.ObjectID &amp;nbsp;&amp;nbsp;&amp;nbsp; poly_lyr = arcpy.MakeFeatureLayer_management("Polygons",'pgon_select',""" "ObjectID" = """+ str(pid)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Watershed is " + str(srow.WATERSHED) &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("Points", "Points_lyr", "", "",&amp;nbsp; ) &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Make point feature layer"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Points_lyr", "INTERSECT", "pgon_select", "", "NEW_SELECTION") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Select points by " + str(srow.WATERSHED) + " watershed"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToTable_conversion("Points_lyr", outTable , str(srow.WATERSHED)+ ".dbf","") &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Make table " + str(srow.WATERSHED) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; srow = srows.next() &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Next Polygon"&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Write .dbf tables to log file" print &amp;gt;&amp;gt; log1, "Files generated = " file_list = os.listdir(outTable) for file in file_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; if file.endswith (".dbf"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log1.write(file + "\n")&amp;nbsp;&amp;nbsp; print "End Processing"&amp;nbsp;&amp;nbsp; log1.close() &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You have neglected to close the cursor when you are done. You must do this, otherwise the cursor stays open -- and you may run into file locking on the next run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;del srows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, using a layer object ("Polygons") with a tool that is attached to an open cursor (outside of directly accessing the geometry or actions like that) is generally bad practice as you are accessing the dataset from two objects at the same time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it is much safer to create a list of unique watershed ids first, closing the cursor and then looping on that list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note the "for" loop construct below. This is the best way to loop through cursors in arcpy (until 10.1 when you should use arcpy.da).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Set a Search Cursor on the Polygons srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" ) sheds= list() for srow in srows: &amp;nbsp; sheds.append(srow.WATERSHED) del row,srows # close/delete cursor variables&amp;nbsp; for shed in sheds: &amp;nbsp; ...&amp;nbsp; &amp;nbsp; arcpy.MakeFeaturelayer_management('"WATERSHED" = \'' + shed + "'"...) &amp;nbsp; ...&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2012 15:55:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26074#M1947</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-09-11T15:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26075#M1948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;mdenil,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Although the Zen is enlightening, the overwrite function still won't work as needed. Is there a specific piece of code you could suggest? I'm a python novice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2012 18:12:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26075#M1948</guid>
      <dc:creator>JennyAxelrod</dc:creator>
      <dc:date>2012-09-11T18:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26076#M1949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;mdenil,&lt;BR /&gt;Although the Zen is enlightening, the overwrite function still won't work as needed. Is there a specific piece of code you could suggest? I'm a python novice.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think what Mark is getting at is inserting something like this before the TableToTable call to explicitly delete the table if it's already there:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
tabName = srow.WATERSHED + ".dbf")
tabPath = os.path.join(outTable,tabName) 
if arcpy.exists(tabPath): arcpy.Delete_management(tabPath)
arcpy.TableToTable_conversion("Points_lyr", outTable , tabName)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, my experience is that arcpy.env.overwriteOutput seems to work fine as long as there are no outstanding file locks (ie active layers pointing to it, etc).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:03:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26076#M1949</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T21:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26077#M1950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi. I ended up here because i was having the same problem. The suggestions here make sense as well. The thing is i don't want to put an &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if arcpy.Exists() &lt;/PRE&gt;&lt;SPAN&gt;for every layer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was having the same problem until i put my section of code between the &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try: 
&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt; 
except: 
&amp;nbsp;&amp;nbsp; &amp;lt;code&amp;gt;&lt;/PRE&gt;&lt;SPAN&gt; and it worked. Why that makes all the difference is beyond me but it might be worth trying because it worked for me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:03:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26077#M1950</guid>
      <dc:creator>DanaDiotte1</dc:creator>
      <dc:date>2021-12-10T21:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26078#M1951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't know if it's a python issue or an ESRI/arcpy issue and I don't know why, but this last tidbit of info (try:except) solved a problem I've been having off and on for months.&amp;nbsp; Halle-freaking-lujah ! Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 14:03:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26078#M1951</guid>
      <dc:creator>LaurelKish</dc:creator>
      <dc:date>2012-10-24T14:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite of output not working</title>
      <link>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26079#M1952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I don't know if it's a python issue or an ESRI/arcpy issue and I don't know why, but this last tidbit of info (try:except) solved a problem I've been having off and on for months.&amp;nbsp; Halle-freaking-lujah ! Thank you.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even better is a try - except - finally, to make sure things are cleaned up no matter what happens. (Layers, table views, open files, cursors, etc.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1 = arcpy.MakeFeatureLayer("myfile.shp","myLyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # ... do stuff with lyr 1
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # ... do stuff you want to do if it fails
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # do stuff you want to do no matter what, for example, try to delete the layer:
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(lyr1)
&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>Fri, 10 Dec 2021 21:03:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwrite-of-output-not-working/m-p/26079#M1952</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T21:03:15Z</dc:date>
    </item>
  </channel>
</rss>

