Hi all,
I'm having some issues with a simple script where I want to write a list of tuples to an empty table in a file geodatabase, where I get the error: RuntimeError: table has no geometry
The FGDB table is a table of seven fields (numbers and text only). The data to insert are built as a list of tuples, like this:
[('275893399', u'4651', u'Nsb - Marienborg', u'02', u'Liten/Ingen kjent p\xe5virkning, med dagens areal/resipientbruk', u'Kommune', u'https://grunnforurensning.miljodirektoratet.no/faktaark.html?lok_id=4651'),
('275893388', u'4651', u'Nsb - Marienborg', u'02', u'Liten/Ingen kjent p\xe5virkning, med dagens areal/resipientbruk', u'Kommune', u'https://grunnforurensning.miljodirektoratet.no/faktaark.html?lok_id=4651')]
My cursor code looks like this:
cursor = arcpy.da.InsertCursor(tab_eksport, fields)
if len(lst) > 0:
for item in lst:
cursor.insertRow(item)
Won't InsertCursor work with no-geometry tables, or is this some other issue?
they work with tables
InsertCursor—Data Access module | ArcGIS Desktop new cursors
InsertCursor—ArcPy Functions | ArcGIS Desktop old cursors
line 4 needs 1 more indent
you have a list of 2 elements of 7 each, but you can't just whip the values in without setvalue
See the code samples in the link above.
Hi! The indentation is a typo, my bad. I can't seem to edit the original post now...
I'm using the same way of "whipping" tuples into tables in another, working, part of the script, and have just reused the code from there. The same can be seen in the first code example in the first link you have, where the input is a tuple. The difference between the working code and this is that in that other case I also have geometry.
I tested your code with desktop 10.5 and could not generate an error with either a table or a feature (w/o geometry). What version are you running? Is it possible the error is associated with another line in your script?
I'm running on 10.3.1.
The error when I run the script (PyScripter) highlights the 'cursor.insertRow()' line in the script. It's possible that it's related to other parts, of course, but as for now I don't have anything to point me in the right direction.
the indentation to begin with as I suggested, unless it is just a bad copy and paste on your part, the indentation is wrong
It's a bad copy/paste, as I explained above. Sorry about that...
Well, I took another look at the script and figured out the problem (<insert red face here>)...
As mentioned above (first reply to Dan), I had two cursors in the script: One writing to a feature class, the other writing to a table. The fields definition was identical, except that the feature class cursor also had geometry. I had, accidentally, used that fields definition for both cursors. When I changed to the correct cursor everything worked fine.