Help with Python Scripting

578
3
03-20-2012 07:18 AM
NoraAllen
New Contributor
I have a database with two tables populated with at least 10,000 records each. I have set up new subtyped fields and want to fill them. However, the editing process is very slow with the amount of data that I have. Is there a way to write a python program that automates the editing process?
Tags (2)
0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
Very likely, yes.

P.S. Try giving more information.
0 Kudos
NoraAllen
New Contributor
I am relatively new at scripting, but what I came up with is this:

cur = arcpy.UpdateCursor(FC)
for row in cur:
    try:
        fieldVal = row.getValue(fieldOne)
        if fieldVal = xxxxxxx:
            value =
            row.setValue(newField, value)

I feel like I am on the right track, but I have no idea how to utilize an existing subtype. How do you bring subtypes into a python program?
0 Kudos
Luke_Pinner
MVP Regular Contributor
First things first... read thisthread and put code tags around your script.

Like so:
cur = arcpy.UpdateCursor(FC)
for row in cur:
    try:
        fieldVal = row.getValue(fieldOne)
        if fieldVal = xxxxxxx:
            value =
            row.setValue(newField, value)


A few issues:

  • a try: statement must have an except: clause

  • equality tests use "==" not "="

  • "value =" needs a value or it will cause a syntax error, i.e. value = "something"

E.g.
cur = arcpy.UpdateCursor(FC)
for row in cur:
    try:
        fieldVal = row.getValue(fieldOne)
        if fieldVal == xxxxxxx:
            value = row.setValue(newField, value)
    except Exception as err:
        Do something useful here or don't use try except at all

For any more assistance you need to give us more info - are you calculating for each of the 2 tables separately, are they joined, do you have to get the value for "newField" from another field in the table/s, etc...?
0 Kudos