Select to view content in your preferred language

overwriteOutput syntax

4565
5
07-02-2012 07:51 AM
by Anonymous User
Not applicable
Original User: MCline19

I am very new to python and am having trouble getting the correct syntax to overwrite existing files.  Using the syntax I have now, the process appends a "_1" to the new output file.  Currently my syntax reads:

import arcpy

for x in sdeFiles: #sdeFiles is a list
     arcpy.env.overwriteOutput = True
     arcpy.FeatureClassToShapefile_conversion(x,'G:\GISAdmin\SDE_Backups\NewTempShapefiles')


Any advise on how to resolve this issue would be greatly appreciated.  Thanks!
0 Kudos
5 Replies
MichaelMiller2
Frequent Contributor
Try:

arcpy.env.overwriteOutput = 1
0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

It still appended a "_1".   😞
0 Kudos
KimOllivier
Honored Contributor
You have a missing r tag to make the path work as a raw string with backslashes, but that is not the issue.
The help clearly says that it will append _1 if the file exists, so it obviously does not honour the environment setting.
So just check if it exists and delete it yourself.

arcpy.env.workspace = "destination_folder"
if arcpy.Exists(x):
     arcpy.management.Delete(x)
arcpy.conversion.FeatureClassToShapefile(x,"destination_folder")
0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

That works.  Good advise!  Thank you.
0 Kudos
GerickeCook
Deactivated User
I had similar issues until I got it to work in my code by using
overwriteOutput = 'True'
0 Kudos