I've encountered an issue implementing a code into ArcMap. The original code was:

for fc in fclist:
... arcpy.Clip_analysis(fc, r’C:\GIS_LabManual\Lab10_Manual\Lab10_data\Arb_clip_poly.shp’, r’C:\GIS_LabManual\Lab10_Manual\Lab10_results\’+fc)

The error it shows is "Parsing error SyntaxError: invalid syntax (line 2)."

I then tried to adjust it to the following code (which also had the same error):

for fc in fclist:
... arcpy.Clip_analysis(fc,r’F:GIS_Joseph\Lab10_Joseph\Data_Joseph\Lab_10_data\Lab_10_data\Arb_clip_poly.shp’,r’F:GIS_Joseph\Lab10_Joseph\Results_Joseph\’+fc)

Could you tell what the error might be?

  • 1
    do you actually have the ... in your code, or did you put it into the question to help show indent? (your actual code should have a tab or a couple spaces, not ...) – KHibma Nov 13 '18 at 16:35
  • go into arc catalog and open the python window. then drag into the window the shapefile you want to clip. It will give you the full and proper path to the file in the window. Then just plug that into your script. – ed.hank Nov 13 '18 at 16:58
  • I did that and it still won't work. It shows the following error: "Parsing error SyntaxError: EOL while scanning string literal (line 2)." – Daniel Joseph Nov 13 '18 at 23:06

I think your single quote characters around the file paths are causing the error. You begin the string with an end quote and end the string with another end quote. Instead of r’C:\path’ try r'C:\path'.

Also, make sure you include a slash after the drive letter in your file path, like you did the first time but not the second time: C:\path as opposed to F:path.

  • Thank you for the response. However, I tried it and it gave me a different error: "Parsing error SyntaxError: EOL while scanning string literal (line 2)." I made sure I have the slash everywhere such as in the following code: for fc in fclist: ... arcpy.Clip_analysis(fc,r'F:\GIS_Joseph\Lab10_Joseph\Data_Joseph\Lab_10_data\Lab_10_data\Arb_clip_poly.shp',r'F:\GIS_Joseph\Lab10_Joseph\Results_Joseph\'+fc) – Daniel Joseph Nov 13 '18 at 23:05
  • 2
    @DanielJoseph you can't have a single slash before the end quote. Make the very last one a double slash Results_Joseph\\'+fc) – Midavalo Nov 14 '18 at 5:54
  • True, the single backslash is a separate issue. From what I've been taught, you can also solve it by changing backslashes to forward slashes in your code. Either way, I think you need to fix that AS WELL AS the single quote characters like I said previously to eliminate all errors. (I tried using your first file path, which did not end with a single backslash, to define a variable, and the ArcMap Python interpreter didn't recognize it as a string and gave me the syntax error you first reported. When I changed the single quote marks, it did recognize the string.) – Matt Leonard Nov 14 '18 at 15:27

Your other issue is that your raw string ends with a backslash. Python doesn't like this.

  File "<stdin>", line 1
SyntaxError: EOL while scanning string literal

Instead, use os.path.join to put your file paths together:

import os.path
for fc in fclist:
    arcpy.Clip_analysis(fc, r’C:\GIS_LabManual\Lab10_Manual\Lab10_data\Arb_clip_poly.shp’, os.path.join(r’C:\GIS_LabManual\Lab10_Manual\Lab10_results', fc))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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