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
52k30 gold badges161 silver badges326 bronze badges
asked Dec 3, 2013 at 15:53
0

1 Answer 1

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.

answered Dec 3, 2013 at 16:09
2

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.