1

I have created a new field called "SFX" in a shapefile called "myshape.shp":

input = r"C:\files\myshape.shp"
arcpy.AddField_management(input, "SFX", "TEXT", field_length=100)

There is now a field called "SFX" but there are no values in the cells. Now, in that same shapefile, I have another field called "SUFFIX".

fields = [field.name for field in arcpy.ListFields(input)]
for field in fields:
 if field == 'SUFFIX':
 print field
>>>'SUFFIX'

Lets say 'SUFFIX' has values 'C', 'D', 'G', etc.... What I want to do, is for each row in 'SFX' I want that cell value to be equal to the corresponding cell value of 'SUFFIX'.

Without making complicated lists using a cursor, how would I do that using UpdateCursor or the Field Calculator?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 4, 2018 at 19:19

3 Answers 3

4

Inserting the code shown below into your if statement should work.

# CalculateField_management (in_table, field, expression, {expression_type}, {code_block})
arcpy.CalculateField_management(in_table="myshape.shp",
 field="SFX",
 expression="!SUFFIX!",
 expression_type="PYTHON_9.3",
 code_block="")
answered Dec 4, 2018 at 19:34
0
4

If you are asking how to calculate SFX field = SUFFIX field then:

import arcpy
shapefile = r'C:\shapefile.shp'
fields = ['SFX','SUFFIX']
with arcpy.da.UpdateCursor(shapefile, fields) as cursor:
 for row in cursor:
 row[0]=row[1]
 cursor.updateRow(row)

Examples like this can be found if you read the help section of da.UpdateCursor.

answered Dec 4, 2018 at 19:38
4

Right click your SUFFIX field, Field Calculator.

In the code block,

SFX = !SUFFIX!
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Dec 4, 2018 at 19:45
0

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.