Select to view content in your preferred language

Python arcpy.da.InsertCursor how to create a newRow()

13290
7
03-04-2016 07:40 AM
JoseSanchez
Frequent Contributor

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)

0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

It doesn't exist any more

InsertCursor—Help | ArcGIS for Desktop

JoseSanchez
Frequent Contributor

So how do I declare the row object now?

0 Kudos
JamesCrandall
MVP Frequent Contributor

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.

Luke_Pinner
MVP Regular Contributor

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...

Methods

insertRow (row)
ParameterExplanationData 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
JamesCrandall
MVP Frequent Contributor

Broken link I think, Dan.

0 Kudos
DanPatterson_Retired
MVP Emeritus

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.

TimothyHales
Esri Notable Contributor

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.