Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select records based on pattern

Status
Not open for further replies.

PDAnalyst

Technical User
Dec 2, 2005
72
US
Hello,

I am trying to write a python code which will be used in GIS environment to select certain records based on the values of a field. I am using Win XP SP3 with Python 2.5.1

Before switching to Python 2.5.1, this VB code section was working in Python 2.4 Ever since the upgrade, VB code does not work.

Basically what I need is for the cursor to go to each record and see if the Address field starts with "LATLONG****" if it does start with that, then write to the Geocode Step "Step2" if not, then write "Step1"

I have tried "LIKE" but python does not like it. If I do it equals to specific LAt and LONG, it works, but there are million pairs of Lat and Long in the city.

Any help is appreciated.

THIS IS THE CODE THAT STOPPED WORKING::::
# Process: Calculate Field...
#gp.CalculateField_management(CFS_Geocode_step1__2_, "GEOCODE_STEP", "Step", "VB", "Dim Step as string\\nIf [Address] LIKE \"LATLONG*\" Then\\nStep = \"STEP2\"\\nElse\\nStep = \"STEP1\"\\nEnd If")


THIS IS THE CODE THAT I AM TRYING TO MAKE IT WORK::::
# Create search cursor for feature class for geocode STEP
rowsearch = gp.searchcursor("C:\\LRMS_ArcMap\\CFS_copy.mdb\\CFS_Geocode_step1","","","Address","")
row = rowsearch.Next()

# Create update cursor for feature class for geocode STEP
path = "C:\\LRMS_ArcMap\\CFS_copy.mdb\\CFS_Geocode_step1"
rows = gp.UpdateCursor(path)
row = rows.Next()

# Update the field Geocode Step based on the value in the field Address
while row:
if row.Getvalue("Address")LIKE'"LATLONG%"':
row.SetValue("GEOCODE_STEP","STEP2")
else :
row.SetValue("GEOCODE_STEP","STEP1")
rows.UpdateRow(row)
row = rows.Next()
print gp.GetMessages()
 
Is that not simply a problem with the indentation ?

You have posted:
Code:
while row:
    if row.Getvalue("Address")LIKE'"LATLONG%"':
       row.SetValue("GEOCODE_STEP","STEP2")
else :
       row.SetValue("GEOCODE_STEP","STEP1")
    rows.UpdateRow(row)
    row = rows.Next()
print gp.GetMessages()
and it should be:
Code:
while row:
    if row.Getvalue("Address")LIKE'"LATLONG%"':
       row.SetValue("GEOCODE_STEP","STEP2")
    else :
       row.SetValue("GEOCODE_STEP","STEP1")
    rows.UpdateRow(row)
    row = rows.Next()
print gp.GetMessages()
 
PDAnalyst said:
Before switching to Python 2.5.1, this VB code section was working in Python 2.4 Ever since the upgrade, VB code does not work.
IMHO something like this
Code:
row.Getvalue("Address")LIKE'"LATLONG%"'
could not work.
Getvalue("Address") is a method.
What should be this part LIKE'"LATLONG%"' ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top