Hello,
I am trying to run a python script and am getting an error. I built a model in Model Builder, and when I run the model in ModelBuilder it works just fine. I then exported it to a python script (.py) and am trying to get it to run in python, but when I do I get an error messages stating "There's an error in your program: *** can't assign to operator (Schools_Excel.py, line 14).
Can anyone help me and let me know what I may be doing wrong after I export the Model to a python script and then run it in python?
Thank you!
Solved! Go to Solution.
You can use the below, i would make sure it was working ad expected first unless you don't care or have a copy of the data
arcpy.env.overwriteOutput = True
EDIT:
Forgot to mention put this line near the top of your script but below import arcpy
a copy of the script would be useful to narrow down the problem.
Here is a copy of the script
# ---------------------------------------------------------------------------
# Schools_Excel.py
# Created on: 2016-04-06 11:30:27.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Local variables:
MAP_Feb_15_2016_-_Copy_xls = "D:\\Schools\\MEMBERSHIP\\MAP Feb 15 2016 Application Status for Program - Copy.xls"
O_MembersExcel = "D:\\MY FILES\\Studies\\Schools\\Schools.gdb\\O_MembersExcel"
IllinoisCity_AddressLocator = "D:\\MY FILES\\Basic Map Data\\IllinoisCity_AddressLocator"
O_Members = "D:\\MY FILES\\Studies\\Schools\\Schools.gdb\\O_Members"
# Process: Excel To Table
arcpy.ExcelToTable_conversion(MAP_Feb_15_2016_Application_Status_for_Program_-_Copy_xls, O_MembersExcel, "O")
# Process: Geocode Addresses
arcpy.GeocodeAddresses_geocoding(FOUO_MembersExcel, IllinoisCity_AddressLocator, "City City VISIBLE NONE;State State VISIBLE NONE", O_Members, "STATIC")
Take the hyphens out see below
MAP_Feb_15_2016_-_Copy_xls
MAP_Feb_15_2016__Copy_xls
Thank you very much Wes. I did that and it got past line 14, but then gave me this error mesage.
Traceback (most recent call last):
File "D:\MY FILES\Scripts\Schools_Excel.py", line 23, in <module>
arcpy.GeocodeAddresses_geocoding(FOUO_MembersExcel, IllinoisCity_AddressLocator, "City City VISIBLE NONE;State State VISIBLE NONE", O_Members, "STATIC")
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\geocoding.py", line 212, in GeocodeAddresses
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000725: Output Feature Class: Dataset D:\MY FILES\Studies\Schools\Schools.gdb\O_Members already exists.
Failed to execute (GeocodeAddresses).
Since you've run this process already the data already exists. Could you rename your output or rename the file you've already created.
The goal is to update the layer on a regular basis, so I would like to just overwrite the data with newly geocoded data. Do you know if there is a way I can overwrite the layer instead of creatinga whole new file?'
I really appreciate your help!!!
You can use the below, i would make sure it was working ad expected first unless you don't care or have a copy of the data
arcpy.env.overwriteOutput = True
EDIT:
Forgot to mention put this line near the top of your script but below import arcpy
Thank you Wes. It didn't originally work, but when I added .env. before the overwrite function it worked (arcpy.env.overwriteOutput = True)!
Thank you again so much for all the help!!!