I've been trying to teach myself Python scripting for ArcGIS and have gotten frustrated on multiple occasions when I try to debug my script endlessly, only to later find out that it actually works properly when it is loaded into the Python shell in ArcGIS. In the past I have received a variety of errors when running the script in PythonWin, only to have the code work just fine when loaded into ArcGIS.
Why is there a discrepancy between the results of a script run in PythonWin and the Python shell in ArcGIS?
I am using:
- Windows 8.1
- Python 2.7.2
- PythonWin (pywin 32 build 214)
- ArcGIS 10.1 Advanced
The script is as follows:
# Import arcpy, env
import arcpy
from arcpy import env
## Enable file overwrite
env.overwriteOuput = True
# Set workspace
env.workspace = "c:/documents/arcgis/arcgis tutorials/psu tutorials/lesson3practiceexercisea/washington.gdb"
# Create new layer feature classes: Cities, ParkAndRide
try:
arcpy.MakeFeatureLayer_management("CityBoundaries", "CityBoundariesLayer")
arcpy.MakeFeatureLayer_management("ParkAndRide", "ParkAndRideLayer")
except:
print "Could not make new layer."
I initially did not post the code because I've had this issue before with code of various types and I was thinking this was not a code error. This code works when loaded the the Python console in ArcGIS, but now when run from PythonWin.
env.overwriteOuputtoenv.overwriteOutput(typo) fixes it. – Jason Scheirer Nov 20 '13 at 01:44