Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am getting "keyword can't be an expression" error while running the following code:

>>> import arcpy
>>> arcpy.MakeFeatureLayer_management("Point","P1","Layer" = 'WM-VALVE-ID')

I ran "Make Feature Layer" tool from the toolbox which worked. Below is the python snippet:

arcpy.MakeFeatureLayer_management("Point","Point_Layer","/\Layer/\ = 'WM-VALVE-ID'","#","OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;Entity Entity VISIBLE NONE;Handle Handle VISIBLE NONE;Layer Layer VISIBLE NONE;LyrFrzn LyrFrzn VISIBLE NONE;LyrLock LyrLock VISIBLE NONE;LyrOn LyrOn VISIBLE NONE;LyrVPFrzn LyrVPFrzn VISIBLE NONE;LyrHandle LyrHandle VISIBLE NONE;Color Color VISIBLE NONE;EntColor EntColor VISIBLE NONE;LyrColor LyrColor VISIBLE NONE;BlkColor BlkColor VISIBLE NONE;Linetype Linetype VISIBLE NONE;EntLinetype EntLinetype VISIBLE NONE;LyrLnType LyrLnType VISIBLE NONE;BlkLinetype BlkLinetype VISIBLE NONE;Elevation Elevation VISIBLE NONE;Thickness Thickness VISIBLE NONE;LineWt LineWt VISIBLE NONE;EntLineWt EntLineWt VISIBLE NONE;LyrLineWt LyrLineWt VISIBLE NONE;BlkLineWt BlkLineWt VISIBLE NONE;RefName RefName VISIBLE NONE;LTScale LTScale VISIBLE NONE;Angle Angle VISIBLE NONE;ExtX ExtX VISIBLE NONE;ExtY ExtY VISIBLE NONE;ExtZ ExtZ VISIBLE NONE;DocName DocName VISIBLE NONE;DocPath DocPath VISIBLE NONE;DocType DocType VISIBLE NONE;DocVer DocVer VISIBLE NONE;ScaleX ScaleX VISIBLE NONE;ScaleY ScaleY VISIBLE NONE;ScaleZ ScaleZ VISIBLE NONE;ID ID VISIBLE NONE;ID_ ID_ VISIBLE NONE;B_P B_P VISIBLE NONE")

So, when I copied the Python snippet into my code and tried running it, I got another error "ERROR 000230: Failed selecting with /\Layer/\ = 'WM-VALVE-ID' Failed to execute (MakeFeatureLayer)."

Any help is very much appreciated.

Thanks Sam

share|improve this question

1 Answer 1

up vote 4 down vote accepted

See arcpy.AddFieldDelimeters for a workaround to this issue. You'd use something like:

layerFld = arcpy.AddFieldDelimiters("C:\data\featureclass.shp", "Layer")
query = layerFld + "='WM-VALVE-ID'"
arcpy.MakeFeatureLayer_management("Point","P1",query)

Hope this helps

share|improve this answer
    
Thank you Stephen. –  Sam Sep 25 '12 at 15:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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