Hello everyone
I am converting a arcpy.InsertCursor in arcpy.da.InsertCursor
How does this line works in arcpy.da.InsertCursor
row = rows.newRow()
# Create insert cursor for table
rows = arcpy.InsertCursor("c:/base/data.gdb/roads_lut")
# Create 25 new rows. Set the initial row ID and distance values
for x in range(1, 26):
row = rows.newRow()
row.setValue("rowid", x)
row.setValue("distance", 100)
rows.insertRow(row)
It doesn't exist any more
So how do I declare the row object now?
arcpy.InsertCursor
# Create insert cursor for table rows = arcpy.InsertCursor("c:/base/data.gdb/roads_lut") # Create 25 new rows. Set the initial row ID and distance values for x in range(1, 26): row = rows.newRow() row.setValue("rowid", x) row.setValue("distance", 100) rows.insertRow(row)
arcpy.da.InsertCursor
fields = ['rowid', 'distance'] cursor = arcpy.da.InsertCursor('c:/base/data.gdb/roads_lut', fields) for x in range(0, 25): cursor.insertRow((x, 100))
Not tested, just going off of the help doc
InsertCursor—Help | ArcGIS for Desktop
Edit: that link doesn't work if clicked, strange. Just copy/paste url into a new browser address box.
Jose Sanchez wrote:
So how do I declare the row object now?
You don't, you pass the values as a list/tuple directly to the insertRow method - it's in the help...
insertRow (row)
Parameter | Explanation | Data Type |
---|---|---|
row [row,...] | A list or tuple of values. The order of values must be in the same order as specified when creating the cursor. When updating fields, if the incoming values match the type of field, the values will be cast as necessary. For example, a value of 1.0 to a string field will be added as "1.0", and a value of "25" added to a float field will be added as 25.0. | tuple |
Broken link I think, Dan.
It has been happening a lot today... Xander and I found one this morning as well, links to the help files are flakey at best Timothy Hales is this due to the impending upgrades? Spotty at best, but links sometimes work and sometimes don't if copied from a help topic.
I am not aware of any issues; however, there are a several issues being fixed with tonight's update. If it continues after the weekend, I will investigate it further.