I am building a script to automate a water outage map(I'm new to Python). In the ArcGIS Desktop 10.1 window the script runs fine. However in Pythonwin and IDLE I get syntax errors(In Pythonwin reads: Failed to run script-syntax error-Invalid syntax). The goal is to use task scheduler to run the script outside of ArcGIS.

enter image description here

import arcpy
mxd = arcpy.mapping.MapDocument(r"X:\Mikes_Workspaces\Outage\Outage.mxd") 
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
# Script arguments
OutCurrent = arcpy.GetParameterAsText(0)
if OutCurrent == '#' or not OutCurrent:
    OutCurrent = "X:\\Geodatabases\\WebData\\Water_Service.gdb\\OutCurrent" # provide a default value if unspecified

# Local variables:
Service_Group = "Service_Group"
Update_ = "X:\\Mikes_Workspaces\\Outage\\Outage_Board.xls\\Update$"
Group_Out = "Service_Group"

# Process: Add Join
arcpy.AddJoin_management(Service_Group, "Group_", Update_, "Group_Out", "KEEP_COMMON")

# Process: Copy Features
arcpy.CopyFeatures_management(Group_Out, OutCurrent, "", "0", "0", "0")
    # Process: Symbology
arcpy.ApplySymbologyFromLayer_management("OutCurrent", "X:\Mikes_Workspaces\Online Shapefiles\Outage_today.lyr") 
# Process: Remove Join
arcpy.RemoveJoin_management(Service_Group, "")
  • I think there must be something else in your script that we are not seeing. Did you post your code by using a ctrl-A/ctrl-C in your script, ctr-V into the edit window here and then apply {} with no other steps?
    – PolyGeo
    Commented Apr 9, 2015 at 22:13
  • 1
    The path in ApplySymbologyFromLayer is not escaped as the others. Can you try that? Also, just curious what you plan is for GetParameterAsText, run from Task Scheduler. edit: it doesn't look like either \M or \O is an escape sequence, so that may not be the issue.
    – phloem
    Commented Apr 9, 2015 at 22:21
  • Did you run the script as a saved file and then via the toolbox, or in the Python window?
    – Erica
    Commented Apr 10, 2015 at 0:13
  • I would suggest to execute each statement one by one in IDLE to identify where the hang up is.
    – artwork21
    Commented Apr 10, 2015 at 1:36
  • RemoveJoin should have the name of the join and not "", try adding the join and removing it in model builder then export that to python to understand the syntax a bit better. Joining with Excel spreadsheets can be a bit flaky and can insert random errors, could you convert it to a file/personal geodatabase table? Commented Apr 10, 2015 at 3:53

3 Answers 3


It appears your Service_Group and Group_Out are just string variables and not an actual GIS layer. You are not setting an environmental workspace, so the various methods will fail that reference these variables. Try setting the environmental workspace before the layer variables are assigned.


arcpy.GetParameterAsText is for accessing parameters in Script Tools.

If you're going to run this outside of ArcGIS, you'll need another way to pass parameters in a command line, such as sys.argv.

Have a look at this page for some examples uses: http://www.tutorialspoint.com/python/python_command_line_arguments.htm

Here's more information on the sys module: https://docs.python.org/2/library/sys.html

  • 2
    Using arcpy.GetParameterAsText(i) outside of script tools works just fine.
    – user2856
    Commented Apr 10, 2015 at 0:42
  • I stand corrected. Good to know.
    – Fezter
    Commented Apr 10, 2015 at 0:43
  • Either works, sys.argv[] is less typing and is all lower case, it's GetParameter that's funny as it expects an object which doesn't convey well on the command line. Commented Apr 10, 2015 at 3:56

Check your code at http://pep8online.com/ It will find things line line 19 where "# Process: Symbology" is indented and python doesn't like that.

I often use print statement to see the progress and variable values, however if it already runs in the python window, your code should be ok, the IDLE and pythonwin are likely to fail on the bad syntax format errors. That website should help clean it up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.