1
arcpy.env.workspace = "Project Path"

feature1 = arcpy.env.workspace+'TableWithEstimates'
feature2 = arcpy.env.workspace+'TableToJoin'

interval = 7

arcpy.CreateTable_management(arcpy.env.workspace,'JustEstimates')
arcpy.management.AddField('JustEstimates', 'FID', 'TEXT')
arcpy.management.AddField('JustEstimates', 'PRICEEST', 'FLOAT')

cur = arcpy.da.UpdateCursor(feature1, ['IN_FID','ESTPRICE'])
cur2 = arcpy.da.InsertCursor('JustEstimates', ['FID','PRICEEST'])

for row in cur:
    if row[0] % interval == 0:
        cur2.insertRow(row)
    else:
        pass
        
del cur, cur2, row

This is an excerpt of the code I am running. The purpose of this is stretch is to take a previously created table and take every seventh row out of it to get the estimates I am looking for. I am going to join this with some other data generated, but need this to work first to match estimate data to another data source.

In Arc's Jupyter platform, I keep getting this error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
In  [2]:
Line 19:    cur2.insertRow(row)

RuntimeError: workspace already in transaction mode
---------------------------------------------------------------------------

This makes no sense as other soultions dealing with problem point to it as a versioning issue. I imported all of this data into a default template from emailed files that also required some jigging. The data should not be versioned since I was the one who created it in ArcGIS Pro.

What could be causing this?

At some point, I did enter this line in a previous Jupyter block.

edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, False)

This addressed the failure of ArcGIS Pro to make the table using the arcpy.CreateTable_management() function. I patched one hole and now I have another and this one is not unpatching.

3
  • Take @BERA point using search cursor and us the keyword 'with' approach like some of the examples at the bottom of the docs page pro.arcgis.com/en/pro-app/latest/arcpy/data-access/… Commented Sep 8, 2021 at 15:18
  • As I walked away from the computer I thought that this was the case. I thought this might be it. Thank you @BERA. I do think this might work. Thank you! I am going to use the with for the search cursor anyway just in case.
    – CaptOle
    Commented Sep 8, 2021 at 17:08
  • 1
    @BERA your solution worked. Please feel free to post it. Thank you!
    – CaptOle
    Commented Sep 8, 2021 at 17:10

1 Answer 1

1

Maybe the updatecursor is blocking the insertcursor from inserting new rows? You dont seem to use it for updating records so you might aswell replace da.UpdateCursor with da.SearchCursor:

...

cur2 = arcpy.da.InsertCursor('JustEstimates', ['FID','PRICEEST'])

with arcpy.da.SearchCursor(feature1, ['IN_FID','ESTPRICE']) as cur:
    for row in cur:
        if row[0] % interval == 0:
            cur2.insertRow(row)
        
del cur2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.