Question

Please can you help, I am struggling how to create a multidimensional array from a loop. I am looping through rows in a data table and want to pass these to an array. Thanks Jay

from Spotfire.Dxp.Data import DataValueCursor
from System import  DateTime, TimeSpan, DayOfWeek
from datetime import date
import time


#define ID
idcursor=DataValueCursor.Create[str](table.Columns["ID"])

#define actual date
actualcursor=DataValueCursor.Create[str](table.Columns["ActualDate"])

#define duration
durationcursor=DataValueCursor.Create[int](table.Columns["Duration"])

#define Start, # of Months and # of days
startcursor=DataValueCursor.Create[int](table.Columns["Start Months"])
monthcursor=DataValueCursor.Create[int](table.Columns["Number of Months"])
daycursor=DataValueCursor.Create[int](table.Columns["Number Of Days"])

#define Min and Max Dates
mincursor=DataValueCursor.Create[str](table.Columns["Min Date"])
maxcursor=DataValueCursor.Create[str](table.Columns["Max Date"])

myPanel = Document.ActivePageReference.FilterPanel
idxSet =    myPanel.FilteringSchemeReference.FilteringSelectionReference.GetSelection(table).AsIndexSet()

bar = []
for row in table.GetRows(idxSet,idcursor,durationcursor,actualcursor,startcursor,monthcursor,daycursor):
#I would like this line to populate the array 
 bar.append(idcursor.CurrentValue)
Was it helpful?

Solution

Dannno had your answer in the comments.

You can do this with:

bar.append([idcursor.CurrentValue, durationcursor.CurrentValue, ...])

note the use of []. This is different from

bar.append(idcursor.CurrentValue, durationcursor.CurrentValue, ...)

as using [] creates an array that contains all the values and appends that array to bar; whereas without [] will attempt to pass each value as a separate parameter to bar.append(), which doesn't work as you discovered.

You also mentioned that you tried:

bar.append(idcursor.CurrentValue)
bar.append(durationcursor.CurrentValue)
...

This will give you a one dimensional array that contains all your values. Since you said you wanted a multi-dimensional array, this won't work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top