syntaxError: EOL while scanning string literal

771
1
02-07-2022 10:18 PM
abdullahAli91
New Contributor

Hi guys,

I am trying to make a new filter with makeFeatureLayer_management . it works fine in arcgis pro as standalone script but while running as a geoprocessing service it shows me an error :

  • esriJobMessageTypeError: File "<string>", line 31 arcpy.MakeFeatureLayer_management(CADSrs, CADlyr,g_ESRI_variable_3'") ^ SyntaxError: EOL while scanning string literal

the code snippet :

arcpy.MakeFeatureLayer_management(CADSrs, CADlyr,"\"Layer\" = 'karar'")

 My question is there any different way to make this filter with python "\"Layer\" = 'karar'"?

I've tried to add r before But it didn't works for me.

Thanks In advance

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

building the whereclause depends on the source of the data. 

Try using AddFieldDelimiters

fc = r"C:\a_path\to\a\file_geodatabase.gdb\featureclass_name"
whereclause = """{} = 'bob'""".format(arcpy.AddFieldDelimiters(fc, 'Name_2'))
whereclause
"Name_2 = 'bob'"

the structure depends on the source


... sort of retired...