simple da.SearchCursor error

782
2
Jump to solution
07-19-2012 10:53 AM
KevinBell
Occasional Contributor III
Ok, I've got other da.SearchCursors that work just fine.  What up with this one???! 

import arcpy  d = {} tbl = r'E:\gis\forestry\20120711_forestryWebApp\temp.gdb\wholeCity' with arcpy.da.SearchCursor('tbl', ['rangeClass', 'count']) as c:     for r in c:  print r[0], r[1]  #d[r[0]] = r[1]   print d


Running this i get:

RuntimeError: cannot open 'tbl'
File "C:\temp\temp.py", line 5, in <module>
  with arcpy.da.SearchCursor('tbl', ['rangeClass', 'count']) as c:


Is it just that I want to jump on my moto and start riding to San Diego?!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Kevin,

You have tbl declared as a variable, and then you declare it as a string with the SearchCursor.  Try the following:

import arcpy  d = {} tbl = r'E:\gis\forestry\20120711_forestryWebApp\temp.gdb\wholeCity' with arcpy.da.SearchCursor(tbl, ['rangeClass', 'count']) as c:     for r in c:         print r[0], r[1]         #d[r[0]] = r[1]      print d

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Kevin,

You have tbl declared as a variable, and then you declare it as a string with the SearchCursor.  Try the following:

import arcpy  d = {} tbl = r'E:\gis\forestry\20120711_forestryWebApp\temp.gdb\wholeCity' with arcpy.da.SearchCursor(tbl, ['rangeClass', 'count']) as c:     for r in c:         print r[0], r[1]         #d[r[0]] = r[1]      print d
0 Kudos
KevinBell
Occasional Contributor III
HA HA HA HA!  I knew I was getting the weekend glazed eyes!  thanks!
0 Kudos