[GIS] Opening table from file geodatabase in ArcPy

arcpyfile-geodatabase

I have tables in a file geodatabase. I want to open and work with them in my script. The first step I appear to have to do is scripted underneath. My result of this script is all names of all tables in my Geodatabase. I would like to also extract all data within these tables. So that I have a matrix or a list of lists in python.

Is this possible?

import arcpy
from arcpy import env

env.workspace = r"D:\data\sre20821\Documents\Voorspelmodel\Geodatabases\2_Component.gdb"

datasetList = arcpy.ListTables("*")

for dataset in datasetList:
     print dataset

http://resources.arcgis.com/en/help/main/10.2/index.html#//002z00000011000000

Best Answer

You can use a cursor to loop through each dataset and print each row.

import arcpy
from arcpy import env

env.workspace = r"D:\data\sre20821\Documents\Voorspelmodel\Geodatabases\2_Component.gdb"

datasetList = arcpy.ListTables("*")

for dataset in datasetList:
     with arcpy.da.SearchCursor(dataset, "*") as cur:
          for row in cur:
              print row

see: http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000