Error in the script

1359
4
05-09-2016 03:41 AM
AlesgerMammedov3
New Contributor


Good day i learned arcpython from Programming ArcGIS 10.1 with Python Cookbook

I write script in the python window. This script add field CONFID_RATING but don't update this field.

Can you help me please

import arcpy, os

... arcpy.env.workspace="C:/ArcpyBook/Ch9/WildfireData/WildlandFires.mdb"

... try:

...     #create a new field to hold the values

...     arcpy.AddField_management("FireIncidents_1","CONFID_RATING","TEXT","10")

...     print "CONFID_RATING field added to FireIncidents"

...     with arcpy.da.UpdateCursor("FireIncidents",("CONFIDENCEVALUE","CONFID_RATING")) as cursor:

...         cntr=1

...         for row in cursor:

...             # update the confid_rating field

...             if row[0]<=40:

...                 row[1]='POOR'

...             elif row[0] > 40 and row[0]<=60:

...               row[1]='FAIR'

...             elif row[0]>60 and row[0]<=85:

...               row[1]='GOOD'

...             else:

...                  row[1]='EXCELLENT'

...             cursor.updateRow(row)

...             print "Record number " + str(cntr) + " updated"

...             cntr=cntr+1

... except Exception as e:

...  print e.message

0 Kudos
4 Replies
AlesgerMammedov3
New Contributor

Why this field don't make update

0 Kudos
NeilAyres
MVP Frequent Contributor

Firstly,

use the advanced editor and the highlight python syntax -Click on that button which looks like ">>".

That would make your code easier to read.

Any errors messages?

Have you tried getting rid of the try/except blocks to see if it just errors out somewhere?

When you look at the data in the table, is "CONFIDENCEVALUE" how you expect it? Numeric?

0 Kudos
AlesgerMammedov3
New Contributor

Thank you for your answer.

I don't get any errors.

But only I get message "CONFID_RATING field added to FireIncidents"

And CONFIDENCEVALUE is Numeric.

0 Kudos
AlesgerMammedov3
New Contributor

I solved it. It was simply, i just only copy this feature class to gdb (WildlandFires.gdb). Then i get my result.

0 Kudos