POST
|
So, something like this, but you have to test it yourself:
import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = "filepath/filepath.gdb"
fc = "FeatureClass"
fields = ('OldField', 'NewField')
#Add the new field
arcpy.AddField_management (fc, "NewField", "TEXT")
# Create update cursor for feature class
#
with arcpy.da.UpdateCursor(fc, fields) as cursor:
# For each row, read the OldField value (index position
# of 0), and update NewField value (index position of 1)
#
for row in cursor:
row[1] = row[0]
# Update the cursor with the updated list
#
cursor.updateRow(row)
PS - Incidentally, you may just have a case-sensitivity error in: cursor.UpdateRow(row) ...since 'UpdateRow' is not recognized, you may fix your own error with 'updateRow'. I just noticed that. My problem was the capitalization, Wayne. Thank you for pointing that out. Being new to Python (programming in general) capitalization kills me. Thank you everyone for the help.
... View more
08-13-2013
04:49 AM
|
0
|
0
|
461
|
POST
|
Taking Wayne's advice into consideration, I have changed the cursor as shown below. However I am not getting any error, but the "NewField" is not updating to reflect the "OldField" values. They are still null. This says to me the script is just skipping the cursor. Any suggestions? import arcpy, string, os, fileinput
from arcpy import env
env.workspace = "filepath/file.gdb"
env.overwriteOutput = True
fc = "feature class"
verification = arcpy.Exists (fc)
print verification
del verification
arcpy.AddField_management (fc, "NewField", "TEXT", "", "", "", "", "", "", "")
fields = ("OldField", "NewField")
with arcpy.da.UpdateCursor (fc, fields) as cursor:
for row in cursor:
row[1] = row[0]
cursor.updateRow(row)
del row
del cursor
... View more
08-12-2013
10:49 AM
|
0
|
0
|
461
|
POST
|
What I am attempting to do is create a copy of an attribute field in a feature class. I want the values of both fields to be exactly the same, but I want their titles to be different. I think I'm close but I am receiving errors, and cannot resolve them myself. import arcpy, string, os, fileinput
from arcpy import env
env.workspace = "filepath/filepath.gdb"
env.overwriteOutput = True
fc = "FeatureClass"
verification = arcpy.Exists (fc)
print verification
del verification
arcpy.AddField_management (fc, "NewField", "TEXT", "", "", "", "", "", "", "")
cursor = arcpy.da.UpdateCursor (fc, "NewField")
for row in cursor:
delimfield = arcpy.AddFieldDelimiters (fc, ["OldField"])
row[0]
cursor.UpdateRow(row)
del row
del cursor I think my issue is here: "delimfield = arcpy.AddFieldDelimiters (fc, ["OldField"])" I'm not even sure this is the right tool for copying over the values from one field to the other. After running the script I receive the error listed below. Any ideas? Runtime error
Traceback (most recent call last):
File "<string>", line 22, in <module>
AttributeError: 'da.UpdateCursor' object has no attribute 'UpdateRow'
... View more
08-12-2013
08:18 AM
|
0
|
6
|
842
|
POST
|
cursor = arcpy.da.UpdateCursor (fc, ["STOINLET_I"])
for row in cursor:
cursor.updateRow([row[0][1:]]) THIS WORKED! Thank you so much.
... View more
08-06-2013
09:11 AM
|
0
|
0
|
1073
|
POST
|
Thanks for such a quick response, Jim. I ran the code with Jim's suggestion, and the code is still kicking up an error, seen here (shell text from IDLE): True Traceback (most recent call last): File "filepath/PythonScript.py", line 16, in <module> row.Replace('P','') AttributeError: 'list' object has no attribute 'Replace' Based upon a quick google search it seems as though people receive this error when their indentation is off, or when filepaths are messy. I managed to account for the filepath with the "verification =" line of code. The blue text reading "true" above confirms the filepath. Also, the spacing in this code is not complicated, and from what I can tell, is correct. Are there any suggestions on how to alleviate this error?
... View more
08-06-2013
08:05 AM
|
0
|
0
|
1073
|
POST
|
Hello all, I am new to Python and, as you can probably guess, I am having issue with some code I'm attempting to write. The following will describe what I am attempting to do, and hopefully you wonderful people can tell me what I'm doing wrong. I have a point feature class with an attribute field called "STOINLET_I." The field looks like this, and has about 2000 entries (rows): PDIN-0001 PDIN-0002 PDIN-0003 PDIN-0004 ... Here is a screenshot, to help better articulate the feature class: [ATTACH=CONFIG]26495[/ATTACH] What I am attempting to do with this script is remove the first character in every row of the field so that the "P" no longer exists, which would leave me with this: DIN-0001 DIN-0002 DIN-0003 DIN-0004 ... I am confident that the first section of code runs successfully. The problem lies within the cursor, but I cannot figure out where. I know this should be easy, but any help would be sincerely appreciated! import arcpy, string, os, fileinput from arcpy import env env.workspace = "desired workspace" env.overwriteOutput = True fc = "desired feature class" verification = arcpy.Exists (fc) print verification del verification cursor = arcpy.da.UpdateCursor (fc, ["STOINLET_I"]) for row in cursor: row.Replace(row[0:],'') del row del cursor
... View more
08-06-2013
06:53 AM
|
0
|
4
|
3081
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|