Invalid Expression or Syntax Error

Discussion created by jazmateta on Aug 10, 2011
Latest reply on Aug 29, 2011 by hzhu
Writing a python script and attempting to use the SelectLayerByAttribute_management command.
I've tried it several different ways and keep getting a syntax error on the variable set, or if the variable set works, get invalid expression.  I am querying against a file geodatabase.

python snippet:

where_clause = (r"Status = 'U'")

arcpy.SelectLayerByAttribute_management("Crimes", "NEW_SELECTION", where_clause)

I'd like to add .outputCount to this to see if there are any rows selected.  I have done this once in the python window but can't remember how I did it now and didn't put it in my script when it worked.

I've also tried various ways of putting quotes and single quotes with and without the r or the parenthesis.  Syntax error or it doesn't get passed properly to the query and gives the Invalid expression.


Forgot to add:  In the ArcMap window using the Select by Attributes dialog, the proper syntax is "Status" = 'U' and it works as expected.  Just can't get the translation to python to work properly.