Error when trying to run Script made from ModelBuilder

3313
8
Jump to solution
04-06-2016 10:39 AM
ISP_graynic
Occasional Contributor II


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!

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
WesMiller
Regular Contributor III

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

View solution in original post

8 Replies
DanPatterson_Retired
MVP Esteemed Contributor

a copy of the script would be useful to narrow down the problem. 

0 Kudos
ISP_graynic
Occasional Contributor II

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")

0 Kudos
WesMiller
Regular Contributor III

Take the hyphens out see below

MAP_Feb_15_2016_-_Copy_xls

MAP_Feb_15_2016__Copy_xls

0 Kudos
ISP_graynic
Occasional Contributor II

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).

0 Kudos
WesMiller
Regular Contributor III

Since you've run this process already the data already exists. Could you rename your output or rename the file you've already created.

0 Kudos
ISP_graynic
Occasional Contributor II

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!!!

0 Kudos
WesMiller
Regular Contributor III

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

ISP_graynic
Occasional Contributor II

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!!!