0

I am doing this:

Access a few columns from a file geodatabase.

arcpy.env.workspace = path
datasetList = arcpy.ListTables("tableA") # Here putting the name of the table

 for dataset in datasetList:
      with arcpy.da.SearchCursor(dataset, ["tablename","query"]) as cur:
           for row in cur:
               print row[0]


RuntimeError: A column was specified that does not exist

This works fine if it reads from a certain table. If I put another table with the same mentioned columns as aliases but different names it gives the error. If aliases can't be used here then what is the usability because now the table has to be recreated with the correct names. It is a problem that it doesn't allow you to rename the columns.

  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. – PolyGeo Oct 31 '18 at 9:04
  • I will form the questions based on the tour next time. Good day! – user51332 Oct 31 '18 at 9:07
2

List the field names using their aliases:

fieldnames = [f.name for f in arcpy.ListFields(dataset) if f.aliasName in ["tablename","query"]]

And then use fieldnames in cursor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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