Select to view content in your preferred language

Syntax Error: Older Version of Python Causing Problems in IDLE?

970
5
Jump to solution
04-16-2013 05:29 PM
DamonOsbourne
Emerging Contributor
Attempting to run a script with IDLE to fix some broken data links in an mxd.  Keep getting this syntax error message, then IDLE highlights the "7" in red as seen in the pic:
[ATTACH=CONFIG]23564[/ATTACH]
I think it has something to do with the fact that I had a previous version of python/IDLE on my machine.  I have since removed it and reinstalled everything, but keep getting the syntax error message.  Would like this script to work in IDLE before moving to other IDE options.  Ideas?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
Ahhh I think I see your problem... It looks like you are trying to run text copied from the interactive python shell as a script. This won't work. You need to delete all the python shell stuff, eg Python 2.7.2 etc... and >>>. and just run the actual commands.


import arcpy.mapping as mapping mxd = mapping.MapDocument("c:/GIS/python/Broken.mxd") mxd.findAndReplaceWorkspacePaths("c:/GIS/python/Old/Trucks.gdb","c:/GIS/python/New/Trucks.gdb") mxd.saveACopy("c:/GIS/python/Fixed.mxd")

View solution in original post

0 Kudos
5 Replies
Luke_Pinner
MVP Regular Contributor
Post your code. From what little I can see in the screenshot, your import statement lacks commas between the modules you want to import.
0 Kudos
DamonOsbourne
Emerging Contributor
Ok, this is what I've got. The error message, though, seems to reflect that header version.

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information
>>> import arcpy.mapping as mapping
>>> mxd = mapping.MapDocument(r"c:/GIS/python/Broken.mxd")
>>> mxd.findAndReplaceWorkspacePaths(r"c:/GIS/python/Old/Trucks.gdb",r"c:/GIS/python/New/Trucks.gdb")
>>> mxd.saveACopy(r"c:/GIS/python/Fixed.mxd")
0 Kudos
BruceNielsen
Frequent Contributor
Since you're using forward slashes in your strings, don't make them raw strings (lose the leading 'r')

r"C:\Temp" = "C:\\Temp" = "C:/Temp"
0 Kudos
Luke_Pinner
MVP Regular Contributor
Ahhh I think I see your problem... It looks like you are trying to run text copied from the interactive python shell as a script. This won't work. You need to delete all the python shell stuff, eg Python 2.7.2 etc... and >>>. and just run the actual commands.


import arcpy.mapping as mapping mxd = mapping.MapDocument("c:/GIS/python/Broken.mxd") mxd.findAndReplaceWorkspacePaths("c:/GIS/python/Old/Trucks.gdb","c:/GIS/python/New/Trucks.gdb") mxd.saveACopy("c:/GIS/python/Fixed.mxd")
0 Kudos
DamonOsbourne
Emerging Contributor
YES, that was it!  Works great now thank you.
0 Kudos