What's the best way to update a dataset and write it back to template parameters?

I would like to update all the values in one column of the dataset, coming from the template parameters of the Template Repeater.

Using setValue() returns a new dataset each time. So, how can I change all the values at once, then push that back to the Repeater's template params? Do I need to convert to a list or dict and back to dataset?

Thanks

The trick is to create a new list of values in one operation, then use our system functions to slice off the old column and drop in a new one. See this thread for a possible approach:

Thanks Paul!

Is there a way to pull a row into a list as well?

Edit:
Got it. Just had to remember this is a pyDataset.

row_list = []
for row in pyDS:
	if row[0] == myZone:
		row_list = row

Is there a row index function for py datasets?

just use pyDS[the number of index]. For example,pyDS[0]

If you really need the row index then you can use enumerate to return an index and the row.

row_list = [[i,row] for i,row in enumerate(pyDs) if row[0] == myZone]

Obviously a contrived example to demonstrate both how to get an index number and how to compress the simple for loop into a comprehension.

2 Likes

I will give that a try.
@nideyijuyidong
Since the PyRow is not aware of it's own row index number, and using range() to loop through the dataset does not provide a list of row data (for a singled out row), I had to look for another option.

@lrose I had a hunch it might involve `enumerate(). I appreciate the "contrived example"! :slight_smile: