1

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 13, 2018 at 16:11
3
  • 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 ...) Commented Nov 13, 2018 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. Commented Nov 13, 2018 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)." Commented Nov 13, 2018 at 23:06

2 Answers 2

4

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.

answered Nov 13, 2018 at 16:45
3
  • 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) Commented Nov 13, 2018 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) Commented Nov 14, 2018 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.) Commented Nov 14, 2018 at 15:27
3

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

x=r'c:\'
 File "<stdin>", line 1
 x=r'c:\'
 ^
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))
answered Nov 14, 2018 at 9:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.