Search code examples
ironpythonspotfire

IronPython Variable keeps getting extra characters during datatable column value assignment in Spotfire


when I run this code it keeps putting in ( and surrounding ' marks.

    for column in dataTable.Columns:
            a=a,column.RowValues.GetFormattedValue(row)

a keeps printing out as this

(('10/13/2015'),'Oranges')

How can I make it just set a=to this

10/13/2015Oranges


Data Table setup

Date        |Fruit
10/13/2015  |Oranges
10/12/2015  |Apples

Solution

  • ah, actually I was looking at this the wrong way. it's not a Spotfire behavior but a normal Python one.

    when you concatenate with ,, you are actually forming a tuple.

    to concat strings, use + instead. the following code works as you like:

    from Spotfire.Dxp.Data import IndexSet
    
    dt = Document.Data.Tables["Data Table"]
    
    rc = dt.RowCount
    ix = IndexSet(rc, True)
    a=""
    
    for row in ix:
        for column in dt.Columns:
            a += column.RowValues.GetFormattedValue(row)
        a += "\n"
    
    print a
    
    > 10/13/2015Oranges
      10/12/2015Apples
    

    you can replicate this in a purely Pythonic environment:

    a = "foo", "bar"
    print(a)
    
    > ('foo', 'bar')
    
    b = "foo" + "bar"
    print(b)
    
    > foobar