1

I have a problem concerning the selection by attribute with python on arcmap.

I use this code:

import arcpy
from arcpy import env
arcpy.env.workspace= "E:\cities"
Mi=(r"E:\cities\rivers.shp")
rows = arcpy.SearchCursor(Mi,'"NAME" = \'Mississippi\'')
row = rows.next()
largeur = row.getValue("MILES")
arcpy.selectLayerByAttribute_management("rivers","New_SELECTION",'"MILES" >' + str(largeur))

And i got this error:

Traceback (most recent call last): File "E:\cities\scripts\Selection.py", line 8, in arcpy.selectLayerByAttribute_management("rivers","New_SELECTION",'"MILES"

' + str(largeur)) AttributeError: 'module' object has no attribute 'selectLayerByAttribute_management'

Échec de l’exécution de (SelectionByAttributes)

Can u help me please??

Aaron
  • 51,658
  • 28
  • 154
  • 317
user24541
  • 69
  • 2
  • 4

1 Answers1

4

To help debug this I would suggest cleaning up the code a bit:

import arcpy
from arcpy import env
arcpy.env.workspace= r"E:\cities" # added raw string indicator `r`

Mi= r"E:\cities\rivers.shp" # removed parentheses - (r"E:\cities\rivers.shp") is a tuple, not a string
rows = arcpy.SearchCursor(Mi,'"NAME" = \'Mississippi\'')
row = rows.next()
largeur = row.getValue("MILES")
where = '"MILES" >' + str(largeur) # let's move the SQL selection clause out here so we can see it
print where
arcpy.selectLayerByAttribute_management("rivers","New_SELECTION",where)

I've removed the parentheses from your variable Mi to make it a string instead of a tuple and moved your SQL query string into a new variable called where - this way we can use a print statement to see what your query looks like. Run this and see if you can determine where your problem is.

Jason Bellino
  • 4,321
  • 26
  • 35