system.dataset.toDataSet
This function is used to 1) convert PyDataSets to DataSets, and 2) create new datasets from raw Python lists
system.dataset. toDataSet( dataset )
-
Parameters
PyDataSet dataset - A PyDataSet object to convert.
-
Returns
Dataset - The newly created dataset.
-
Scope
All
system.dataset. toDataSet( headers, data )
-
Parameters
PySequence headers - The column names for the dataset to create.
PySequence data - A list of rows for the new dataset. Each row must have the same length as the headers list, and each value in a column must be the same type.
-
Returns
Dataset - The newly created dataset.
-
Scope
All
#This first example shows how this function can be used to convert from a PyDataSet (which is what system.db.runQuery returns) to a normal DataSet, which is the datatype of a Table component's data property.
pyDataSet
=
system.db.runQuery(
"SELECT * FROM example1 LIMIT 100"
)
table
=
event.source.parent.getComponent(
"Table"
)
normalDataSet
=
system.dataset.toDataSet(pyDataSet)
table.data
=
normalDataSet
#This second example shows how to use this function to create a new dataset out of a Python sequence that you have filled in. In this case, the sequence is created via a for loop appending rows to a list.
#Generate the Rows
rows
=
[]
for
x
in
range
(
10
):
oneRow
=
[
"Row %d"
%
x, x
+
15
]
rows.append(oneRow)
#Generate the DataSet
headers
=
[
"RowID"
,
"Value"
]
data
=
system.dataset.toDataSet(headers, rows)
#Use our new dataset to fill in a Table
table
=
event.source.parent.getComponent(
"Table"
)
table.data
=
data