overwriteOuput works in ArcMap's Python Window but not in PythonWin

2077
9
12-09-2011 04:11 AM
BruceKessler
New Contributor
Hi all,

This has to be simple, but it's driving me a bit crazy at the moment. The following code works fine and allows overwriting when using the Python Window in ArcMap v10 sp3.

[INDENT]arcpy.env.workspace = "C:\\Data\\Assessors.gdb"
arcpy.env.overwriteOutput = "True"
arcpy.Buffer_analysis("FireCalls", "FireBuff", "1000 Meters")[/INDENT]

When I put this into a script in PythonWin and run it with the following code:

[INDENT]import arcpy
arcpy.env.workspace = "C:\\Data\\Assessors.gdb"
arcpy.env.overwriteOutput = "True"
arcpy.Buffer_analysis("FireCalls", "FireBuff", "1000 Meters")[/INDENT]

I get 'Ouput ... already exists' as an error.

I seem to have a basic problem here and I'm not figuring it out. I can even print the value of arcpy.env.overwriteOutput in the PythonWin program and it comes out as True. It just seems that ArcGIS is not recognizing this.

Am I doing something wrong?
Tags (2)
0 Kudos
9 Replies
StephanieWendel
Esri Contributor
There could be something wrong with the PythonWin install. Your code works fine when I use a sample geodatabase dataset version in PythonWin. Try running the same script in IDLE and see what you get. Maybe try working with a different output name and see if that makes a difference for doing the overwrite output.
0 Kudos
DanPatterson_Retired
MVP Emeritus
instead of
arcpy.env.overwriteOutput = "True"

try a boolean instead of a text string
arcpy.env.overwriteOutput = True

or
arcpy.env.overwriteOutput = 1
0 Kudos
BruceKessler
New Contributor
There could be something wrong with the PythonWin install. Your code works fine when I use a sample geodatabase dataset version in PythonWin. Try running the same script in IDLE and see what you get. Maybe try working with a different output name and see if that makes a difference for doing the overwrite output.


Thanks. That got me to thinking that I should stop/start PythonWin...

DANGIT! It works fine now...

You can't imagine how much frustration little things like this cause me... well, I bet you can as you've probably been in a similar situation.

Thank you.
0 Kudos
BruceKessler
New Contributor
instead of
arcpy.env.overwriteOutput = "True"

try a boolean instead of a text string
arcpy.env.overwriteOutput = True

or
arcpy.env.overwriteOutput = 1


Thanks, Dan. I actually tried all those permutations to no avail. Look at my above posting for the "duhhhh" solution.
0 Kudos
DanPatterson_Retired
MVP Emeritus
If you are developing and testing scripts, it is often useful to include a

reload(arcpy)

line after the initial import, nothing gets changed once arcpy gets loaded until you quit python or pythonwin, hence, a reload causes arcpy to get reinstantiated removing the need to quit and start again.  Once script development is done, then you can comment out the line.  This applies to other modules that are imported, including user-developed ones, or numpy etc etc.
0 Kudos
BruceKessler
New Contributor
Thanks, Dan.
0 Kudos
DennisPringle
New Contributor
I am having the same problem as Kessler. When I run the following program from PythonWin it works fine the first time when the output file does not exist, but fails the second time immediately after despite indicating that overwriting is enabled. It likewise fails from IDLE. This happens after rebooting the machine and without at any stage running ArgGIS (which is 10.1). There are no lock files that I can see. I am running XP SP3 in case that has any relevance.

import arcpy
from arcpy import env
env.workspace = "d:\Temp"
env.overwiteOutput = True
if env.overwiteOutput:
    print "Overwriting is set to True"   #This line is indented in the script
arcpy.Clip_analysis("parks.shp","zip.shp","parks_clip.shp")
print arcpy.GetMessages()

Overwriting is set to True

Traceback (most recent call last):
  File "D:\Temp\my_clip.py", line 7, in <module>
    arcpy.Clip_analysis("parks.shp","zip.shp","parks_clip.shp")
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\analysis.py", line 56, in Clip
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000725: Output Feature Class: Dataset d:\Temp\parks_clip.shp already exists.
Failed to execute (Clip).

I have repeated the experiment with the exact same results on a different machine (also XP SP3) except this time I ran IDLE before running PythonWin in case PythonWin was somehow corrupting things. (Okay, I know I am grasping at straws, but this is really bugging me).

When the script is cut and paste in the Python window in ArcGIS is works fine.

Anyone any ideas? Please.
0 Kudos
DanPatterson_Retired
MVP Emeritus
spelling
env.overwiteOutput
should be
env.overwriteOutput
0 Kudos
DennisPringle
New Contributor
Thanks Dan. You have saved my sanity, although at this stage nothing can save my self esteem! I cannot believe that I not only misspelled it, but misspelled it twice. (I could have sworn I was using the autocomplete, but obviously not).
0 Kudos