Select to view content in your preferred language

Calling arcpy.env.overwriteOutput

4170
2
03-16-2012 09:00 AM
JohanSmith
Emerging Contributor
How do I go about calling the arcpy.env.overwriteOutput function?
i.e. [ATTACH=CONFIG]12779[/ATTACH]

The print statement clearly shows that it is 'True' but my if else statment is not calling it in the same manner.

J
Tags (2)
0 Kudos
2 Replies
JasonScheirer
Esri Alum
== True
, not
== 'True'
, the quotes matter
0 Kudos
curtvprice
MVP Alum
The quotes matter


The reason the quotes matter is arcpy.env.overwriteOutput is a boolean value, not text, no matter how you set it.

>>> arcpy.env.overwriteOutput = 'True'
>>> arcpy.env.overwriteOutput
True
>>> arcpy.env.overwriteOutput = 1
>>> arcpy.env.overwriteOutput
True


Fortunately for you, it seems, Esri has set things up so if you set it this property to  'False' (string) it evaluates to False. (Normally in Python, any non-null string evalulates to boolean True.)

>>> arcpy.env.overwriteOutput = 'False'
>>> arcpy.env.overwriteOutput
False
>>> bool('False')
True


Also since it is boolean type your original test can be written more simply:

if arcpy.env.overwriteOutput:
  print "It is true!"
else:
  print "It is false!"
0 Kudos