How to get handle of a known data table
Question: I am hoping to figure out the answer of a seemingly simple question. Below I
was trying to get the handle of a known table, by the name of "TableMe". Being
able to print its name back on the screen would prove that I have got the
handle correctly.

    
    
    from Spotfire.Dxp.Data import *
    from Spotfire.Dxp.Application import *
    
    # Trial #1
    #dataTable = Document.Data.Tables["TableMe"]
    
    # Trial #2
    dataTable = Document.ActiveDataTableReference
    print dataTable.Title
    

Both my Trial #1 and #2 had failed, for different reasons:

Trial #1:

    
    
    AttributeError: 'getset_descriptor' object has no attribute 'Tables'
    

Trial #2:

    
    
    AttributeError: 'getset_descriptor' object has no attribute 'Title'
    

I feel that this must be a simple question for any fluent IronPython
programmers. Can someone shed a light or two pls?


Answer: you don't need to import anything to access data tables:

    
    
    for table in Document.Data.Tables:
        print table.Name
        print table.Id
        print table.RowCount
        print "---"
    

then to access a specific table:

    
    
    table = Document.Data.Tables["TableMe"]
    

...or if you have the ID:

    
    
    tID = "abc123"
    table = Document.Data.Tables[tID]
    

...or by index (refer to the Data Table Properties dialog in Spotfire for the
order, make sure to start at zero):

    
    
    table = Document.Data.Tables[0]
    

